Results 1 to 3 of 3

Thread: Problem With simple program

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149

    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 -|-
    Email: [email protected]
    Website: http://www.hurgh.org/

    Unix, Linux, FreeBSD, OpenBSD, Solaris, Windows

    C, C++, PHP, VB6, ASP, VBScript, JavaScript

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    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?
    Last edited by Wynd; Aug 23rd, 2001 at 06:28 PM.
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149
    Thanks Wynd

    I didnt remember that there was not ment to be ; at the end of for statments and that, i removed them and recompiled it and now it works properly.

    Thanks for your help.


    -|- Hurgh -|-
    Email: [email protected]
    Website: http://www.hurgh.org/

    Unix, Linux, FreeBSD, OpenBSD, Solaris, Windows

    C, C++, PHP, VB6, ASP, VBScript, JavaScript

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width