主要没有看到声明的全局变量。 [英] Declared global variable isn't being seen by main.

查看:66
本文介绍了主要没有看到声明的全局变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我为什么giv_len在这个声明中没有出现

以下printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len)"


= cut


#include< stdio.h>

#include< stdlib.h>


char delimiter =''\ n'';

unsigned long long int cur_len = 0L;

int giv_len;

unsigned long int record = 0L;


int main(int argc,char * argv [])

{

char * infile = argv [1];

char * outfile = argv [2];

giv_len = atoi(argv [3]);

printf(" giv_len is:%d \ n",giv_len);


FILE * i = fopen(infile," r");

FILE * o = fopen(outfile," w");

int ch;

while((ch = fgetc(i))!= EOF){

++ cur_len;


if(ch ==分隔符){

++记录;

/ * printf("%d \ n&q UOT;,cur_len); * /

if(cur_len!= giv_len){

printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len);

fprintf(o,记录%d错误长度:%d \ n,记录,cur_len);

}

cur_len = 0;

}

}

fclose(i);

fclose(o);

返回0;

}

解决方案

Tr***********@gmail.com 写道:


有人能告诉我为什么giv_len在这个声明中没有出现

以下printf("记录%d错误长度:% d应为%d

\ n",record,cur_len,giv_len)"



答案是因为你骗了printf(),告诉它cur_len

变量是一个int。 />

更正你的printf()语句格式字符串,以反映

第二个变量值是unsigned long long的事实,你的问题应该去

远离。


= cut


#include< stdio.h>

#include< stdlib.h>


char delimiter =''\ n'';

unsigned long long int cur_len = 0L;

int giv_len;

unsigned long int record = 0L;


int main(int argc,char * argv [])

{

char * infile = argv [1];

char * outfile = argv [2];

giv_len = atoi(argv [3]);

printf(" giv_len is:%d \ nn",giv_len);


FILE * i = fopen(infile," r");

FILE * o = fopen(outfile," w ");

int ch;

while((ch = fgetc(i))!= EOF){

++ cur_len;


if(ch == delimiter){

++ record;

/ * printf("%d \ N'QUOT;,cur_len); * /

if(cur_len!= giv_len){

printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len);

fprintf(o,记录%d错误长度:%d \ n,记录,cur_len);

}

cur_len = 0;

}

}

fclose(i);

fclose(o);


返回0;

}



- -

Lew Pitcher


Master Code Code& JOAT-in-training |已注册的Linux用户#112576
http://pitcher.digitalfreehold.ca/ |可根据要求提供GPG公钥

---------- Slackware - 因为我知道我在做什么。 ------


更改为以下内容:


printf("记录%lu错误长度:%llu应该是%d

\ n",record,cur_len,giv_len);


无效

3月13日,8:32 pm,Lew Pitcher< lpitc ... @ teksavvy.comwrote:


Tristin.Co ... @ gmail.com写道:


有人能告诉我为什么giv_len在这个声明中没有出现

以下printf("记录%d错误长度:% d应为%d

\ n",record,cur_len,giv_len)"



答案是因为你通过告诉它cur_len

变量是一个int来欺骗printf(。) />

更正你的printf()语句格式字符串,以反映

第二个变量值是unsigned long long的事实,你的问题应该去

离开。


= cut


#include< stdio。 h>

#include< stdlib.h>


char delimiter =''\ n'';

unsigned long long int cur_len = 0L;

int giv_len;

unsigned long int record = 0L;


int main(int argc,char * argv [])

{

char * infile = argv [1];

char * outfile = argv [2];

giv_len = atoi(argv [3]);

printf(giv_len is:%d \ n,giv_len);


FILE * i = fopen(infile," r");

FILE * o = fopen(outfile, " w");

int ch;

while((ch = fgetc(i))!= EOF){

++ cur_len;


if(ch == delimiter){

++ record;

/ *的printf(QUOT;%d\\\
",cur_len); * /

if(cur_len!= giv_len){

printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len);

fprintf(o,记录%d错误长度:%d \ n,记录,cur_len);

}

cur_len = 0;

}

}

fclose(i);

fclose(o);


返回0;

}



-

Lew Pitcher


Master Code Code& JOAT-in-training |已注册的Linux用户#112576http://pitcher.digitalfreehold.ca/ |可根据要求提供GPG公钥

---------- Slackware - 因为我知道我在做什么。 ------


我想我想通了。我在一个窗户盒子里(使用minGW)。也许它

当我将它更改为unsigned long

并且相应地更改格式时,它不会支持很长的b / c。它可以工作。


任何方式我可以解决这个问题并获得很长时间吗?

3月13日晚上8:40,Tristin.Co ... @ gmail.com写道:


更改为以下内容:


printf("记录%lu错误长度:%llu应为%d

\ n",record,cur_len,giv_len);


无效


3月13日,8日:32 pm,Lew Pitcher< lpitc ... @ teksavvy.comwrote:


Tristin.Co ... @ gmail.com写道:
< blockquote class =post_quotes>
有人能告诉我为什么giv_len在这个声明中没有出现

以下printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len)"


答案是因为你骗了printf()告诉它cur_len

变量是一个int。


更正你的printf()语句格式字符串,以反映

第二个变量值是无符号长long的事实,你的问题应该去

了。


= cut


#include< stdio.h>

#include< stdlib.h>


char delimiter =''\ n'';

unsigned long long int cur_len = 0L;

int giv_len;

unsigned long int record = 0L;


int main(int argc,char * argv [])

{

char * infile = argv [1];

char * outfile = argv [2];

giv_len = atoi(argv [3]);

printf(" giv_len is:%d \ nn",giv_len);


FILE * i = fopen(infile," r");

FILE * o = fopen(outfile," w");

int ch;

while((ch = fgetc(i))!= EOF ){

++ cur_len;


if(ch == delimiter){

++记录;

/ * printf("%d \ nn",cur_len); * /

if(cur_len!= giv_len){

printf("记录%d错误长度:%d应该是%d

\ n",record,cur_len,giv_len);

fprintf(o,记录%d错误长度:%d \ n,记录,cur_len);

}

cur_len = 0;

}

}

fclose(i);

fclose(o);


return 0;

}


-

Lew Pitcher


Codewright大师& JOAT-in-training |已注册的Linux用户#112576http://pitcher.digitalfreehold.ca/ |可根据要求提供GPG公钥

---------- Slackware - 因为我知道我在做什么。 ------


Can someone tell me why giv_len isn''t being seen in this statement
below "printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len)"

=cut

#include <stdio.h>
#include <stdlib.h>

char delimiter = ''\n'';
unsigned long long int cur_len = 0L;
int giv_len;
unsigned long int record = 0L;

int main(int argc, char *argv[])
{
char* infile = argv[1];
char* outfile = argv[2];
giv_len = atoi(argv[3]);
printf("giv_len is :%d\n",giv_len);

FILE* i = fopen(infile,"r");
FILE* o = fopen(outfile,"w");
int ch;
while((ch=fgetc(i) ) != EOF) {
++cur_len;

if(ch == delimiter) {
++record;
/*printf("%d\n",cur_len); */
if(cur_len != giv_len) {
printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len);
fprintf(o,"Record %d wrong length:%d\n",record,cur_len);
}
cur_len=0;
}
}
fclose(i);
fclose(o);
return 0;
}

解决方案

Tr***********@gmail.com wrote:

Can someone tell me why giv_len isn''t being seen in this statement
below "printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len)"

The answer is "because you lied to printf() by telling it that the cur_len
variable was an int".

Correct your printf() statement format string to reflect the fact that the
second variable value is an unsigned long long, and your problem should go
away.

=cut

#include <stdio.h>
#include <stdlib.h>

char delimiter = ''\n'';
unsigned long long int cur_len = 0L;
int giv_len;
unsigned long int record = 0L;

int main(int argc, char *argv[])
{
char* infile = argv[1];
char* outfile = argv[2];
giv_len = atoi(argv[3]);
printf("giv_len is :%d\n",giv_len);

FILE* i = fopen(infile,"r");
FILE* o = fopen(outfile,"w");
int ch;
while((ch=fgetc(i) ) != EOF) {
++cur_len;

if(ch == delimiter) {
++record;
/*printf("%d\n",cur_len); */
if(cur_len != giv_len) {
printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len);
fprintf(o,"Record %d wrong length:%d\n",record,cur_len);
}
cur_len=0;
}
}
fclose(i);
fclose(o);
return 0;
}

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I''m doing. ------


changed to the following:

printf("Record %lu wrong length:%llu Should be %d
\n",record,cur_len,giv_len);

to no avail
On Mar 13, 8:32 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:

Tristin.Co...@gmail.com wrote:

Can someone tell me why giv_len isn''t being seen in this statement
below "printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len)"


The answer is "because you lied to printf() by telling it that the cur_len
variable was an int".

Correct your printf() statement format string to reflect the fact that the
second variable value is an unsigned long long, and your problem should go
away.

=cut

#include <stdio.h>
#include <stdlib.h>

char delimiter = ''\n'';
unsigned long long int cur_len = 0L;
int giv_len;
unsigned long int record = 0L;

int main(int argc, char *argv[])
{
char* infile = argv[1];
char* outfile = argv[2];
giv_len = atoi(argv[3]);
printf("giv_len is :%d\n",giv_len);

FILE* i = fopen(infile,"r");
FILE* o = fopen(outfile,"w");
int ch;
while((ch=fgetc(i) ) != EOF) {
++cur_len;

if(ch == delimiter) {
++record;
/*printf("%d\n",cur_len); */
if(cur_len != giv_len) {
printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len);
fprintf(o,"Record %d wrong length:%d\n",record,cur_len);
}
cur_len=0;
}
}
fclose(i);
fclose(o);

return 0;
}


--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I''m doing. ------


I think i figured it out. I''m on a windows box(using minGW). maybe it
doesn''t support long long b/c when i change it to just unsigned long
and change the format accordingly, it works.

Any way I can work around this and get the long long?
On Mar 13, 8:40 pm, Tristin.Co...@gmail.com wrote:

changed to the following:

printf("Record %lu wrong length:%llu Should be %d
\n",record,cur_len,giv_len);

to no avail

On Mar 13, 8:32 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:

Tristin.Co...@gmail.com wrote:

Can someone tell me why giv_len isn''t being seen in this statement
below "printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len)"

The answer is "because you lied to printf() by telling it that the cur_len
variable was an int".

Correct your printf() statement format string to reflect the fact that the
second variable value is an unsigned long long, and your problem should go
away.

=cut

#include <stdio.h>
#include <stdlib.h>

char delimiter = ''\n'';
unsigned long long int cur_len = 0L;
int giv_len;
unsigned long int record = 0L;

int main(int argc, char *argv[])
{
char* infile = argv[1];
char* outfile = argv[2];
giv_len = atoi(argv[3]);
printf("giv_len is :%d\n",giv_len);

FILE* i = fopen(infile,"r");
FILE* o = fopen(outfile,"w");
int ch;
while((ch=fgetc(i) ) != EOF) {
++cur_len;

if(ch == delimiter) {
++record;
/*printf("%d\n",cur_len); */
if(cur_len != giv_len) {
printf("Record %d wrong length:%d Should be %d
\n",record,cur_len,giv_len);
fprintf(o,"Record %d wrong length:%d\n",record,cur_len);
}
cur_len=0;
}
}
fclose(i);
fclose(o);

return 0;
}

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I''m doing. ------


这篇关于主要没有看到声明的全局变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆