Re: Declared global variable isn't being seen by main.
- From: Lew Pitcher <lpitcher@xxxxxxxxxxxx>
- Date: Thu, 13 Mar 2008 21:32:07 -0400
Tristin.Colby@xxxxxxxxx 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. ------
.
- Follow-Ups:
- Re: Declared global variable isn't being seen by main.
- From: Tristin . Colby
- Re: Declared global variable isn't being seen by main.
- References:
- Declared global variable isn't being seen by main.
- From: Tristin . Colby
- Declared global variable isn't being seen by main.
- Prev by Date: Re: Is it conformant to substract two pointer-to-void ?
- Next by Date: Re: Declared global variable isn't being seen by main.
- Previous by thread: Declared global variable isn't being seen by main.
- Next by thread: Re: Declared global variable isn't being seen by main.
- Index(es):
Relevant Pages
|