Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C:没有错误,编译成功,但没有运行_C - Fatal编程技术网

C:没有错误,编译成功,但没有运行

C:没有错误,编译成功,但没有运行,c,C,我正试图建立自己的小型库,以处理超过int或double限制的巨大数字的计算。我知道有一些用于此目的的有用库,但我只是自己尝试一下 在下面的代码中,我找不到错误,编译器(MinGW的gcc)也找不到错误。它根本不运行。我重新阅读了多次代码,但仍然无法理解为什么我的计算机拒绝运行它。顺便说一下,我用的是Windows7。任何帮助或建议都将不胜感激 (该代码旨在打印11111…………111111111.11111) #包括 #包括 #定义+10 #定义负11 作废myprint(字符f[]); in

我正试图建立自己的小型库,以处理超过int或double限制的巨大数字的计算。我知道有一些用于此目的的有用库,但我只是自己尝试一下

在下面的代码中,我找不到错误,编译器(MinGW的gcc)也找不到错误。它根本不运行。我重新阅读了多次代码,但仍然无法理解为什么我的计算机拒绝运行它。顺便说一下,我用的是Windows7。任何帮助或建议都将不胜感激

(该代码旨在打印11111…………111111111.11111)

#包括
#包括
#定义+10
#定义负11
作废myprint(字符f[]);
int getlen(char f[]);
void daeip(字符f[],字符g[]);
/*
(len:数组f[]的长度)
f[len-3]:数字的开始;数字部分从f[f[len-3]]到f[0]
f[len-2]:小数位数
f[len-1]:加号或减号
*/
int main(){
字符f[100],g[100];
int i;
对于(i=0;i=0;i--){
printf(“%s”,f[i]);
如果(i==f[len-2])printf(“.”);
}
}
int getlen(字符f[]{
int len=sizeof(f)/sizeof(f[0]);
回程透镜;
}
void daeip(字符f[],字符g[]{
int flen=getlen(f);
内格伦=格伦(g);
int i;

对于(i=0;i您在printf语句中使用了%s,它需要一个指向字符串(char数组)的指针作为参数。 您应该使用%c。它需要一个字符作为参数。换句话说,更改:

printf(“%s”,f[i]);
to
printf(“%c”,f[i]);

详情:

char[] test = "This is a test";
char firstCharacter = test[0];// 'T'

// The following will print out: This is a test
printf("%s", test);
// The following will be unpredictable, and may cause a runtime error. (even though it compiles)
printf("%s", firstCharacter);
// The following will print out 'T'
printf("%c", firstCharacter);

我还建议您创建一个结构或类,这样您就可以将长度、十进制位置和符号与实际数字分开。

注意:
int len=sizeof(f)/sizeof(f[0]);
不符合您的要求。注2:f[]数组可能不是以null结尾的。您应该学习如何使用调试器,仅仅阅读代码通常不足以找到bug。@wildplasser的意思是,当您将数组传递给函数时,它将成为指向数组第一个元素的指针。您还需要将元素数传递给函数。它可能无法修复所有问题,但t它应该对调试有很大帮助。欢迎这么说。对于这样的问题,澄清“不运行”的含义会很有用-它是否表示程序启动但不输出任何内容,或者它崩溃,或者其他什么?您忽略了
char f[]
在函数参数列表中
char*f
。数组不能按值传递。
getlen
无法知道
main
f[]
的原始长度。
char[] test = "This is a test";
char firstCharacter = test[0];// 'T'

// The following will print out: This is a test
printf("%s", test);
// The following will be unpredictable, and may cause a runtime error. (even though it compiles)
printf("%s", firstCharacter);
// The following will print out 'T'
printf("%c", firstCharacter);