Tag: c

注册Windows类Win32

注册win32程序的窗口类的最佳做法是什么? 您是否在WinMainfunction中注册每个课程或者是否需要?

计算C中的行,单词和字符

下面是我的计算行数,单词和字符的函数 – void count(char* file) { int fd; long end=0; char c; long words=0; long lines=0; if((fd=open(file, O_RDONLY))>0){ end=lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); while(read(fd, &c, 1)==1){ if(c == ‘ ‘) words++; if(c == ‘\n’) { lines++; words++; } } printf(“The Number of characters in file is: %ld\n”,end); printf(“The Number of lines in file is: […]

使用未分配的空间calloc

我只是想知道当我使用非分配空间时编译器不会抛出exception,这里是一个代码例如: #include #include int main() { int i, n; int *a; printf(“Number of elements to be entered:”); scanf(“%d”,&n); a = (int*)calloc(n, sizeof(int)); printf(“Enter %d numbers:\n”,n); for( i=0 ; i < n ; i++ ) { scanf("%d",&a[i]); } printf("The numbers entered are: "); for( i=0 ; i < n ; i++ ) { printf("%d ",a[i]); } […]

使用C ++导入注册表文件

我有一些问题,让以下简单的代码正确运行: #include int main( void ) { system(“foo.reg”); //why does this NOT WORK?! //system(“reg import foo.reg”); //why does this NOT WORK?! //system(“regedit \”foo.reg\””); //why does this NOT WORK?! return 0; } 注册表文件位于已编译的可执行文件所在的目录中。 当我从命令行运行它时, foo.reg运行成功,但运行上面的程序只显示regedit确认窗口,并且在注册表本身没有相应的更改。 我使用Dev-C ++编写程序,我运行的是Windows XP x64 SP2。 任何帮助将不胜感激。

用C ++执行脚本

我想通过c ++程序执行脚本并获取其输出。 现在我在做 system(“./script.sh > out.txt”); 但是我需要一个命令来将输出转换为字符串,例如: out = system(“./script.sh”); printf(out); 执行脚本后我无法读取文件out.txt,因为我没有权限。 我在其他框架(boinc)上部署了我的c ++程序,但没有给我这个权限。 有人有提示吗? 提前致谢! 费利佩

__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] 那怎么解决这个问题????