Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Learning C


  • Please log in to reply
5 replies to this topic

#1 xx66stangxx

xx66stangxx

  • Members
  • 139 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:O.C.
  • Local time:02:16 PM

Posted 06 July 2006 - 01:13 PM

#include <stdio.h>

int x, y;

int main (void )
{
for (x=0; x<10; x++, printf ("\n") )
for (y=0; y<10; y++)
printf( "%c", 1 );

return 0;
}

BC AdBot (Login to Remove)

 


m

#2 Grinler

Grinler

    Lawrence Abrams


  • Admin
  • 43,388 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:05:16 PM

Posted 06 July 2006 - 01:20 PM

Helping in chat. The problem is that when he runs the program it shows the console prompt quickly and then exits. This is because its a console program and needs to be run from the console. If you want to see the output when you run from Bloodshed Dev C++ you need to add a pause in there that will keep the program running until you press any key. This can be done via:

#include <stdio.h>

int x, y;

int main (void )
{
for (x=0; x<10; x++, printf ("\n") )
for (y=0; y<10; y++)
printf( "%c", 1 );
system("PAUSE");
return 0;
}

The system("PAUSE"); will pause the program till you press any key allowing you to see the output from the console program.

#3 xx66stangxx

xx66stangxx
  • Topic Starter

  • Members
  • 139 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:O.C.
  • Local time:02:16 PM

Posted 06 July 2006 - 01:26 PM

#include <stdio.h>

int x, y;

int main (void )
{
for (x=0; x<10; x++, printf ("\n") )
for (y=0; y<10; y++)
printf( "%c", );
system ("PAUSE") ;

return 0;
}


and this is what shows up
c:\docume~1\owner\mydocu~1\hello.c: In function `main':
c:\docume~1\owner\mydocu~1\hello.c:9: parse error before `)'

Edited by xx66stangxx, 06 July 2006 - 01:28 PM.


#4 Grinler

Grinler

    Lawrence Abrams


  • Admin
  • 43,388 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:05:16 PM

Posted 06 July 2006 - 01:28 PM

Your missing your argument for the printf statement. Make it:

printf("%c",1);

like you had previously.

#5 xx66stangxx

xx66stangxx
  • Topic Starter

  • Members
  • 139 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:O.C.
  • Local time:02:16 PM

Posted 06 July 2006 - 01:29 PM

sweet it worked thanks!

#6 Swandog46

Swandog46

  • Members
  • 134 posts
  • OFFLINE
  •  
  • Local time:06:16 PM

Posted 07 July 2006 - 09:34 AM

There are a number of problems here:

1) Your variables x and y are global since they are declared outside the main() function. This is considered bad form because if you want to use a variable somewhere else called 'x', you will overwrite this one or have unexpected effects. Keep variables local whenever possible (almost always).

2) The program will print out 10 newlines, and then print out 10 instances of an unprintable character whose ASCII representation is 1. This is almost certainly not what you wanted. If you wanted the actual character '1' printed out, you would need to do:

printf("%c", '1');

since '1' is the ASCII representation of the character 1 (it's actually 49 I believe), whereas just a plain 1 will actually be the number 1.

Edited by Swandog46, 07 July 2006 - 09:35 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users