LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2007, 04:47 PM   #1
sjcorp
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Rep: Reputation: 0
Question C program


I have copied this program into pico and compiled it using cgg. Then I get an error that states, "Badly placed ()'s." Everything I'm reading tells me it should be done like this, so, I need assistance from experts. What am I doing wrong?

#include <stdio.h>

int main()
{
int this_is_a_number;

printf( "Please enter a number: " );
scanf( "%d", &this_is_a_number );
printf( "You entered %d", this_is_a_number );
getchar();
}
 
Old 10-14-2007, 05:40 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Please post code inside [code] tags. This helps improve readability by using a fixed-width font and preserving whitespace.

What command are you using to compile and link the program. There is no cgg. Perhaps you mean gcc? Please post the exact command you used, and the output of that command.

As far as I can see, your program should build OK. You should get into the habit of putting the argc and argv parameters to main, and explicitly return an integer value (0 for success, 1-127 for other statuses).
 
Old 10-14-2007, 07:50 PM   #3
sjcorp
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you. I did mean gcc. I copied the program into pico, and then ran gcc ctest.c. That reported nothing. Then, I typed at the command prompt "./ctest.c". That's when it errored with "Badly placed ()'s." I copied the program from a tutorial on line.
 
Old 10-14-2007, 08:12 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,817

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
Code:
alucard@thrawn:~$ cat c.c
#include <stdio.h>

int main()
{
  int this_is_a_number;

  printf( "Please enter a number: " );
  scanf( "%d", &this_is_a_number ); 
  printf( "You entered %d\n", this_is_a_number );
  getchar();
}
alucard@thrawn:~$ gcc -o c c.c
alucard@thrawn:~$ ./c
Please enter a number: 1
You entered 1
alucard@thrawn:~$
Works for me.

I see what you're doing. You don't execute ctest.c, you execute the program produced by gcc. In my example the "-o c" named it "c". In yours, you got the default name, which iirc is "a.out". Try ./a.out or passing "-o outputname" to gcc.
 
Old 10-14-2007, 08:18 PM   #5
sjcorp
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you very much. I tried ./a.out, and that did it. I'm really glad you are there to help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM


All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration