Problem With simple program
Hi, how are you all,
I am just starting out teaching myself C, and the C++, and i have written a simple program that is ment to produce:
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
But instead it just makes a 10 line space, meaning it has like 10 new lines and no X's.
Here is the source,
Code:
#include <stdio.h>
int x,y;
main()
{
for ( x = 0; x < 10; x++, printf( "\n" ) );
for ( y = 0; y < 10; y++);
printf( "X" );
return 0;
}
I compiled it on bot Windows, using Turbo C (the old old borland program), and that worked fine, then i tried to compile it on Linux Debian and that is where i have the problem.
This is the command line that i use to compile it on linux:
(assumes that the file name is ex0103.c)
gcc ex0103.c
Can someone please let me know what is wrong with the source code for linux, y does it work under windows but not in linux??
Thanks for your time
-|- Hurgh -|-
Re: Problem With simple program
Code:
#include <stdio.h>
int x,y;
main()
{
for ( x = 0; x < 10; x++, printf( "\n" ) );
for ( y = 0; y < 10; y++);
printf( "X" );
return 0;
}
Try removing the semicolons.
Or, try this:
Code:
#include <stdio.h>
main()
{
for (int i = 1; i <= 10; i++)
printf("XXXXXXXXXX\n");
return 0;
}
From what I understand it seems like you want 10 X's and a newline, but it isn't happening?