__try / __最终在UNIX中等效

我有一个主要用C语言编写的库,它的某些部分应该是线程安全的,我使用全局自旋锁来保护代码的关键部分。 现在我的问题是: 我应该从一个受自旋锁保护的关键部分内部调用一些用户回调,如果那些回调生成exception,在Windows上我有一个_ try / _finally在C中,即使在离开临界区时也是如此发生错误。 我也可以在UNIX上完成这个吗?

在’ – >’标记之前预期的unqualified-id,如何解决这个问题?

struct box { char word[200][200]; char meaning[200][200]; int count; }; struct root { box *alphabets[26]; }; struct root *stem; struct box *access; void init(){ int sizeofBox = sizeof(struct box); for(int i = 0 ; icount = 0; root->alphabets[i] = temp; //error line } } 错误:在’ – >’标记之前预期的unqualified-id 如何解决这个bug。 谁能解释一下这是什么类型的?

c中用户定义函数的冲突类型

很长一段时间后我在c工作。我必须实现三个function,包括 得到一个数字并显示一半 2.获取数字的平方 3.获取两个数字并显示它们的总和和消除。 我正在使用devC ++,当我编译代码时,我得到了我在标题中提到的错误, conflict type if squareInput这里有什么问题: #include #include int main(){ float x; printf(“enter a number\n”); scanf(“%f”,&x); //TASK 1 : display half of the number pirntf(“half of x is = %.3f”,x); //TASK 2 : square of number squareInput(x); //call square function from here // TASK 3 : get two numbers and display […]

无需等待即可从用户那里获得输入 – C语言..!

我正在编写一个简单的计时器,它从00s到55s运行,然后再从00开始计数,并一直计数直到用户停止计时。 为此,我为用户提供了两个选项:1。启动和2.重置。 选择第一个运行程序,并选择第二个,因为我认为,将把计时器转为00s并保持在那里。 现在我面临的问题是我希望在不停止计时器的情况下从用户那里获得输入(即,在程序运行时允许用户随时输入2,这样他就可以停止正在进行的计数)。 我试图使用像getch()和scanf()这样的函数,但它们正在停止计时器,这完全破坏了程序。 任何帮助赞赏的人.. !!

将Char *缓冲区转换为hex,以便在c 中打印

嗨我试图将char缓冲区中的值打印为hex值为(“0X%x”), char buffer[1024] printf(“recived (0x%x) from the client\n”,buffer); 但编译代码时有警告: server.c:105:5: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘char *’ [-Wformat] 那怎么解决这个问题????

在C中打印数组时出现分段错误

#include #include #include //This program is a sorting application that reads a sequence of numbers from a file and prints them on the screen . The reading from the file here , is a call back function . typedef int (*CompFunc)(const char* , const char* ); typedef int (*ReadCheck)(char nullcheck); char array[100]; //Let this function […]

如何读取一系列空格分隔的整数,直到遇到换行符?

我一直在尝试编写一个程序来读取一系列空格分隔的整数,直到遇到换行符。我的方法是将输入作为字符串读取并使用atoi()将字符串转换为整数。 这是我的方法: #include #include #include int main() { int a[100],i=0,k=0; char s[100]; //Read the first character scanf(“%c”,&s[i]); //Reads characters until new line character is encountered while(s[i]!=’\n’){ i+=1; scanf(“%c”,&s[i]); } //Print the String printf(“\nstring = %s\n”,s); //Trying to convert the characters in the string to integer for(i=0;s[i]!=’\0′;i++){ if(isdigit(s[i])) { a[k] = atoi(s); k+=1; } } //Printing […]

C中的void函数如何与指针一起使用?

我试图在C编程中创建一个与指针一起使用的void函数。 我创建了以下与指针一起使用的函数: #include int function_1(int *num1, int *num2) { int *total; *total = *num1 / *num2; return *total; } int main(void) { int numerator; int denominator; int finalAnswer; printf(“Numerator: “); scanf(“%d”, &numerator); printf(“Denominator: “); scanf(“%d”, &denominator); finalAnswer = numerator / denominator; printf(“%d / %d = %d \n”, numerator,denominator,finalAnswer); } 这个程序没有问题,但是当我改变后的第一行时 #include 对此: void function_1(int *num1, […]

移位负的有符号值是不确定的

我主演原始的JPEG标准( ITU 81 ),特别是图F.12:扩展V中解码值的符号位 : 作为参考, SLL术语表示: shift left logical operation (参见PDF的第15页) 现在着名的libjpeg实现决定以这种方式实现它(非常直接的转录): /* * Figure F.12: extend sign bit. * On some machines, a shift and add will be faster than a table lookup. */ #ifdef AVOID_TABLES #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) #else #define HUFF_EXTEND(x,s) ((x) […]

对于c中的猜谜游戏,无法获得除“太高”以外的结果

我已经完成了一个程序的代码,该程序允许用户输入一系列值来猜测,然后随机生成数字,然后允许用户猜测并报告太低,太高或正确。 当我测试程序运行时,我只得到“太高”的输出。 我已经尝试调试并查看我的代码,但我无法看到它出错的地方。 任何帮助深表感谢! #include #include int main() { int min, max, number, guess, count = 0; printf(“Please enter two integers for the range:\n”); scanf(“%d %d”, &min, &max); number = (min + rand()%(max – min + 1)); printf(“I’m thinking of a number between %d and %d.\n”, min, max); printf(“Enter your guess:\n”); scanf(“%d”, &guess); while(guess != […]