Tag: 数组

如何解决“参数有不完整类型”的错误?

我是新手,我需要帮助调试我的代码。 当我编译它”forms参数1的类型不完整’和forms参数2的类型是不完整的’错误出现在 printf(“Age is %d years.\n”, calc_age(birth, current)); 而’参数1(’出生’)具有不完整类型’和’参数2(’当前’)具有不完整类型’错误出现在 int calc_age (struct date birth, struct date current) { 感谢帮助,谢谢! #include int calc_age (struct date birth, struct date current); int main(void) { struct date { int month[1]; int day[1]; int year[1]; }; struct date birth, current; char c; printf(“Input the birthdate (MM/DD/YY): “); scanf(“%d %c %d […]

将文件列表保存到数组或其他内容C

我有这个function void file_listing(){ DIR *dp; struct stat fileStat; struct dirent *ep; int file=0; dp = opendir (“./”); if (dp != NULL){ while ((ep = readdir(dp))){ char *c = ep->d_name; char d = *c; /* first char */ if((file=open(ep->d_name,O_RDONLY)) d_name); } else{ continue; /* altrimenti non lo listo */ } } } (void) closedir (dp); } […]

〜没有对stdout的反应〜在C

#include #include #include int main() { int a,query,in,n,b[n],sum[a]; sum[1]=0; scanf(“%d”,&query); for(a=1;a<=query;a++) { scanf("%d",&in); for(n=1;n<=in;n++) { b[n]=1+7*(n-1)+6*(n-1)*(n-2)+(n-1)*(n-2)*(n-3); sum[a]=sum[a]+b[n]; } } for(a=1;a<=query;a++) { printf("%d\n",sum[a]); } return 0; } 我已经制作了这个在终端上运行的代码。 但是在黑客排名中它显示出来了 输入(stdin) 2 2 5 你的输出(标准输出) ~ no response on stdout ~ 预期产出 9 225 编译器消息 Segmentation Fault 现在我该怎么做才能解决问题。

字符串终止符’\ 0’如何与整数常量0具有相同的值?

我有以下代码 – #include #define LENGTH 5 int main(){ char* ch[LENGTH] = {“Zero”, “One”, “Two”, “Three”, “Four”}; char* pc; char** ppc; for(int i=0; i<LENGTH; i++){ ppc = ch+i; pc = *ppc; while(*pc != 0){ printf("%c ", *pc); pc = pc +1; } printf("\n"); } return 0; } 它是使用字符串的多个间接的示例。 输出是 Z ero O ne T wo T […]

在C中传递2D指针数组

对于我的程序,我需要将一个2D数组指针传递给一个单独文件中的函数。 我在下面写了一个类似语法的文件: #include #include typedef struct { int state; int design; } card_t; card_t *cardSet[5][5]; void setFirst(card_t *cards[][]) { // state = 1; } int main() { setFirst(cardSet); // <- Error: Type of formal parameter 1 is incomplete return 0; } 当我将代码更改为所有1D数组时,它编译得很好,但对于2D数组,我得到上面显示的错误。 这两种情况有什么区别? 谢谢! 卡梅伦

在C中,是否保证1/2 == 0?

在C中保证1/2 == 0 ? 我需要它来实现二进制搜索: /* * len is the array length * ary is an array of ptrs * f is a compare function * found is a ptr to the found element in the array * both i and offset are unsigned integers, used as indexes */ for(i = len/2; !found && i […]

移动字符串数组中的元素并用零填充

我想将我的数组中的元素向右移动并用零填充移位的元素(作为字符串)。 但它比我想象的要困难一些。 该程序读取包含两行的文本文件。 每行包含一个整数(定义了最大长度)。 它将每一行保存在一个单独的数组中。 我需要稍后将这两个数组转换为整数数组并进行一些算术运算。 所以为此,我需要确保这两个数组具有相同的长度 例如我的输入是: num_first: 1859654 num_second: 5654 现在我需要他们: num_First: 1859654 (它比第二个数字大,所以不会改变) num second: 0005654 (比第一个小,所以我们需要添加那些前导零 ) 如何根据两个输入的差异将那些前导零添加到数组? 最后我想将它们保存在数组中(如字符串或整数)。 #include #include #define SIZE_MAX 20 int main() { FILE *fPTR; char num_first[SIZE_MAX]; // string input char num_second[SIZE_MAX]; if ((fPTR = fopen(“input.txt”, “r”)) == NULL) // our file contains two line of integers. […]

使用C,从textFile打印出一个数组

我正在尝试创建一个从纺织品中读取的代码,然后将数据存储到内存中,打印到屏幕上以便用户可以读取它,但它仍然保存在内存中,以便您可以将其用于其余部分该计划.. 这是纺织品的样本 75 nevermind nvm not much nm no problem np people ppl talk to you later ttyl because cuz i don’t know idk as soon as possible asap yeah ya how are you hru you 列表继续,它总共有150个单词,如果包含第一个数字,则为151行。 75用于告诉你有多少对。 无论如何,这是我到目前为止编写的代码,它使用这个结构 typedef struct { char *English; char *TextSpeak; }Pair; 我到目前为止编写的代码是: FILE *infile =fopen(“dictionary.txt”,”r”); int phraseCounter; fscanf(infile, “%i”, […]

C:从textfile读取到struct数组中

我正在制作的程序应该从文本文件中读取数字并保存数字的总数,即结构中数字的平均值。 我有一个看起来像这样的结构: struct seriepost { int totnr; int outnr; float average; }; function(未完成)看起来像这样: int read_data(FILE *tsin, struct seriepost serie[]) { int x = 0; float average = 0; float in_last = 0; while (!feof(tsin)) { while (fscanf(tsin, “%f”, &in_last) != 0.0) { serie[x].totnr += 1; serie[x].medel = average/serie[x].totnr; serie[x].outnr = average*1.05+average*0.95; } x += 1; […]

如何创建struct数组

我想实现一个搜索表,这里是数据: 20130610 Diamond CoinMate 11.7246 15.7762 2897 20130412 Diamond Bithumb 0.209 0.2293 6128 20130610 OKCash Bithumb 0.183 0.2345 2096 20130412 Ethereum Chbtc 331.7282 401.486 136786 20170610 OKCash Tidex 0.0459 0.0519 66 … 和我的代码 typedef struct data{ int *date; string currency[100]; string exchange[100]; double *low; double *high; int *daily_cap; } Data; int main() { FILE *fp […]