为什么在下面的第一个fscanf函数中,%s的参数没有&但是%d的参数有&?
fscanf(fileR, "%s%d", meds[count].name, &meds[count].unitsInStock);
==> meds[count].name, &meds[count].unitsInStock
fscanf(fileR, "%i", &meds[count].sixmth[i]);
==> &meds[count].sixmth[i]发布于 2017-11-09 21:41:50
因为字符串已经是一个指针,我将在这个示例中解释它:
int * buff;
int n;
buff = &n;
//&n - address of n
//buff - address of n
//*buff - value of n
fscanf(stdin, "%d", &n); //it is only variable, it needs to pass address of it
fscanf(stdin, "%d", buff); //it is pointer to variable, it doesn't need to add &对于字符串(char*),它是相同的:
char* str;
str = malloc(50);
fscanf(stdin, "%s", str); //it is poitner, there is already addresshttps://stackoverflow.com/questions/47211854
复制相似问题