By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

Aaarrrrgh! can't even make printf() work...

P: n/a
The following 2 code segs seem to be the cause of my output infinite
loop.
Can someone tell me if this is wrong? I'd like to post the entire
program, but that seems to distract everyone who migh post from the
actual functional glitch.
for (row = 0; row < 52; row++) /* dump array into text file
*/
{
fprintf (fileptr, "\n");
for (col = 1; col < 121; col++) {
fprintf (fileptr, "%2d ", current[row][col]);
}
}

fclose(fileptr);
return 0;
}

************************************************** ****************

for (row = 0; row < 52; row++)
{
printf("\n");
for (col = 1; col < 121; col++) {
printf ("%i ", current[row][col]);
}
}
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a


Blankdraw wrote:
The following 2 code segs seem to be the cause of my output infinite
loop.
Can someone tell me if this is wrong? I'd like to post the entire
program, but that seems to distract everyone who migh post from the
actual functional glitch.
What is the declaration of the array.
Is it:
int current[52][120]; ?

If so, you have an error in the for loop.


for (row = 0; row < 52; row++) /* dump array into text file
*/
{
fprintf (fileptr, "\n");
for (col = 1; col < 121; col++) {
for(col 0; col < 120,col++) {
fprintf (fileptr, "%2d ", current[row][col]);
}
}

fclose(fileptr);
return 0;


--
Al Bowers
Tampa, Fl USA
mailto: xa*@abowers.combase.com (remove the x)
http://www.geocities.com/abowers822/

Nov 13 '05 #2

P: n/a
On 19 Aug 2003 20:02:16 -0700, sp********@aol.com (Blankdraw) wrote:
The following 2 code segs seem to be the cause of my output infinite
loop.
Can someone tell me if this is wrong? I'd like to post the entire
program, but that seems to distract everyone who migh post from the
actual functional glitch.


Assuming correct definitions for row, col, current and fileptr and
that <stdio.h> is included there is no problem with the code you
posted.

How about a *minimal* but complete program that exhibits the problem?

Nick.

Nov 13 '05 #3

P: n/a
On 19 Aug 2003, Blankdraw wrote:
The following 2 code segs seem to be the cause of my output infinite
loop.
Can someone tell me if this is wrong? I'd like to post the entire
program, but that seems to distract everyone who migh post from the
actual functional glitch.
Looking at the code below I see nothing that will cause an infinite loop.
It must be something you have not included. You want to create a stand
alone snippet that exhibits the same, incorrect, behaviour. Usually, doing
that will make the problem obvious.

What is missing to make this a stand alone program? You need an #include
<stdio.h>, you need variable declarations, you need a main function. Once
you put that together look at it again and see if the problem still
occurs. If it does not then the trick is figuring out what is in the
original program that is missing from the snippet. Again, be the time you
figure that out the problem should be obvious. If not, post the code
snippet that compiles.
for (row = 0; row < 52; row++) /* dump array into text file
*/
{
fprintf (fileptr, "\n");
for (col = 1; col < 121; col++) {
fprintf (fileptr, "%2d ", current[row][col]);
}
}

fclose(fileptr);
return 0;
}
On a guess, are these the variable declarations?

int row, col, current[52][120];

You might have gotten the indices backwards. Why is col = 1 the start for
the inner loop? Just a curiosity but probably not part of your problem.

Another thought, have you stepped through the code with a debugger? How do
you know it is an infinite loop? The fprintf statement might not write to
the file until the fclose occurs. If you look at the file and see it is
not changing, maybe the changes are buffered. Try adding a fflush(fileptr)
after the fprintf.

Another thought, did the fopen work okay? Did you check the results? Is it
using the correct mode?

Anything else will be wild guessing so I'll stop here.
************************************************** ****************

for (row = 0; row < 52; row++)
{
printf("\n");
for (col = 1; col < 121; col++) {
printf ("%i ", current[row][col]);
}
}


--
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}

Nov 13 '05 #4

P: n/a

"Vijay Kumar Zanvar" <vi*****@hotpop.com> wrote in message
news:bh************@ID-203837.news.uni-berlin.de...

olaf wrote in message ...
Hello

The only thing I can get up is did you open the file. you close it,
but where do you open it.

Greetings Olaf

int dump(int **current)
{
FILE *fileptr=NULL;
fileptr = fopen("c://file.txt","w");


This should be fileptr = fopen ( "c:\\file.txt", "w" )


And you should *always* check the return type.
Nov 13 '05 #5

P: n/a
In article <qS****************@news.abs.net>, en**********@yahoo.comI-
WANT-NO-SPAM says...
fileptr = fopen("c://file.txt","w");


This should be fileptr = fopen ( "c:\\file.txt", "w" )


And you should *always* check the return type.


type? :-)

Nov 13 '05 #6

P: n/a
Fao, Sean <en**********@yahoo.comi-want-no-spam> wrote:
"Vijay Kumar Zanvar" <vi*****@hotpop.com> wrote in message
news:bh************@ID-203837.news.uni-berlin.de...

olaf wrote in message ...
>Hello
>
>The only thing I can get up is did you open the file. you close it,
>but where do you open it.
>
>Greetings Olaf
>
>int dump(int **current)
>{
>FILE *fileptr=NULL;
> fileptr = fopen("c://file.txt","w");
This should be fileptr = fopen ( "c:\\file.txt", "w" )

And you should *always* check the return type.


ITYM: value

Alex
Nov 13 '05 #7

P: n/a
Randy Howard <ra**********@FOOmegapathdslBAR.net> wrote in message news:<MP************************@news.megapathdsl. net>...
In article <qS****************@news.abs.net>, en**********@yahoo.comI-
WANT-NO-SPAM says...
> fileptr = fopen("c://file.txt","w");

This should be fileptr = fopen ( "c:\\file.txt", "w" )


And you should *always* check the return type.


type? :-)


Oops, sorry about that! I mean value.
Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.