分配给类型时不兼容的类型 – 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 […]

通过scanf_s读取字符时访问冲突写入位置

每当我尝试读取诸如3 + 5类的表达式时,我一直遇到“访问违规写入位置” #include add(double a, double b, int prec); int main() { int prec; double a, b; char oper; printf(“Enter Precision: “); scanf_s(“%d”, &prec); if (prec<0) { printf("This is not a valid precision value"); } printf("%d", prec); printf("Enter Expression: "); scanf_s("%lf %c %lf", &a, &oper, &b); … }

c – 在2d数组中检查null

我从输入文件中填充10 x 10个字符的网格。 我需要检查网格是否是正方形(即,有N×N个字符,其中N <= 10) 输入文件是这样的: pitk olpe pkey tope 当我在gdb中打印网格时,我得到以下结果: $1 = {“pitk\000\000\000\000\366h”, “olpe\000\000\001\000\000”, “pkey\000\000\000\000\000”, “tope\000\000\000\000\000”, “\000\344\241\367\377\177\000\000”, , “\000\377\377\177\000\000\037\355\336”, , “\000\177\000\000\000\000\000\000\000”, “\000\000\000\000\000\000\000\000\000”, “\000\000\000\000\000\000\000\000\r\020”, “\000\000\000\000\000\000\000\000\000”} 我的主函数中检查网格是否有效的部分是: bool check = (checknxn(grid)); if(check == false) { fprintf(stderr, “Invalid Input!\n”); exit(0); } checknxn函数: bool checknxn(char grid[10][10]) { int columns = 0; for(int i=0;i<10;i++) { if(grid[0][i]!=NULL) columns++; else […]

为什么将scanf()的结果与NULL进行比较会产生编译器警告?

我用C语言写作,我需要阅读输入中的所有内容,但我不知道会收到多少个字符。 我写 while (scanf(“%c”, &read) != NULL) 但是编译器告诉我: [Warning] comparison between pointer and integer ,那么我应该写什么呢?

使用typedef动态分配Matrix

我已经知道如何在矩阵中使用malloc如果它是一个int** 。 但是使用typedef ,我认为有一个想法,但我不太确定。 typedef int LabeledAdjMatrix[SIZE][SIZE]; 我这样做吗? APSP = (APSPMatrix*)malloc(sizeof(APSPMatrix)); 但是当我访问它时,我将不得不使用*APSP[0][0] ,我不知道如何在memset / memcpy使用它。 有没有正确的方法呢? 无论是动态分配还是访问。

Scanf被忽略

#include #define length 20 main() { float x; int y; float array1[length], array2[length], array3[length]; float ray[length]; int size1 = insert(array1, length); printf(“enter number: “); scanf(“%d”, &y); int size2 = insert(array2, length); int size3 = insert(array3, length); } int insert(float a[], int size) { int n = 0; while(n<size && scanf("%f\n", &a[n]) == 1) { printf("you […]