Tag: c

将具有NULL字节的C字符串转换为char数组

我正在使用具有多个选择function的GetOpenFileName 。 挑选的文件在LPSTR中返回。 在此LPSTR中,所选文件由NULL字节分隔。 我想将LPSTR拆分成一个数组,然后遍历该数组。 在PHP中我会这样做: $array = explode(“\0”, $string); 但由于我是C的新手,我不知道自己在做什么。

打印无循环

可能重复: 在没有循环或条件的情况下打印1到1000 #include #include int fun(int n) { –n && fun(n); return printf( “\n%d”, n+1); } int main(void) { fun(1000); getch(); return 0; } 这是一个不使用循环或if-else打印1到1000的程序。 是否有其他方法可以不使用循环或if-else。

在单个malloc()调用中创建2D数组

#include #include #define MAX_ROWS 5 #define MAX_COLS 5 int globalvariable = 100; void CreateMatrix(int ***Matrix) { int **ptr; char *cp; int i = 0; *Matrix = (int**)malloc((sizeof(int*) * MAX_ROWS) + ((MAX_ROWS * MAX_COLS)*sizeof(int))); ptr = *Matrix; cp = (char*)((char*)*Matrix + (sizeof(int*) * MAX_ROWS)); for(i =0; i < MAX_ROWS; i++) { cp = (char*)(cp + ((sizeof(int) […]

如何重置字符串中的位值?

在最近的采访中我得到了一个这样的问题: Given a string value, find out its 127th bit and reset it, do this in C language Reset means if that particular bit is 0 change to 1 and vice versa 我没有找到任何算法,但我想知道如何用C语言解决这个问题。 编辑: 从少数人得到答案后,我尝试了这个: #include void main() { char *str=”anto”; str[15] ^= 0x80; printf(“%s”,str); } 我得到的输出为: anto 。 现在我的头脑中有一点点改变一点不会改变输出?

从fortran写出二进制文件并在C中读取

我正在尝试读取一个由fortran程序生成的二进制文件。 我的输出中有一些奇怪的字符,难道这两个fortran和C都有不同的endianess吗?

分配给类型时不兼容的类型 – C

我在C中的一个项目中使用Code :: Blocks。 当我编译时,我得到错误:“在第81,85,90,91行上从类型’double’分配类型’double *’时不兼容的类型”。 该项目是采用单位转换工具并包含多个函数,而不是main()下的所有内容。 http://pastebay.net/1181184

我如何在c中使用enqueue函数对列表进行排序?

我的列表 : list= C,3 –>C,5,—> A,7 –> A,5 –> G,2–> C,11 –>A,4 我的输出: output= C,5 C,11 G,2 A,7 A,4 A,5 C,3 但是有一些错误。 我在答案中编写代码,然后编写charcmp函数并用strcmp替换为charcmp。 它有时会发挥作用。 但通常第一个元素是在错误的地方。我的排序​​代码喜欢答案的代码

c – 错误:在非结构或联合的情况下请求成员xxxxxx

这是一个旨在使用ppm图像文件的程序。 我在尝试使用接受全局结构变量并提取该图像成员的函数时遇到编译错误。 这是全局结构(在ppmIO.c和ppmIO.h中声明): ppmIO.c: struct Image *instance; ppmIO.h: struct Image { int width; int height; unsigned char *data; }; extern struct Image *instance; 这就是我从main调用我的函数的方法: ImageInvert(&instance); 这些是我的imageManip.c文件的相关部分: #include #include #include #include #include void ImageInvert(struct Image **toInvert) { int i; int pix = (*toInvert->width) * (*toInvert->height); for (i = 0; i data = ((unsigned char)255 – *(toInvert)->data)); […]

错误:在’&’标记|之前预期’;’,’,’或’)’ 在线发现一个简单的C程序

我在网上找到了这个程序来练习C.当我尝试在Code块中编译这个程序时,我在’&’token |“之前在两个地方收到此错误”错误:预期’;’,’,’或’)’ (在代码中提到)。 如果有人能解释我错误的原因,那将非常有帮助。 #include int f1(int x,int y) { x=x+2; y=y+3; return x+y;} int f2(int &x,int y) //error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token| { x=x+2; y=y+3; return x+y; } int f3(int *x,int *y) { *x = *x+2; *y = *y+3; return *x+*y; } int f4(int x,int &y,int *z)//error: expected ‘;’, ‘,’ […]

创建单独的子函数来计算文件中的每个字母

我正在尝试为每个需要在文件中计数的letter创建单独的child process 。 我在parent process读取文件,但输出全为零。 我不明白我做错了什么。 我需要为每个字母使用子进程,但我不确定如何为每个字母创建单独的进程。 请帮忙! 这是我的代码: #include #include #include #include #include #include #include int main(int argc, char **argv){ char characters[26] = { “abcdefghijklmnopqrstuvwxyz” }; int counter[26] = { 0 }; int n = 26; int c; char ch; if (argc < 2) return 1; pid_t pids[26]; for (int i = 0; i […]