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

C programming question


  • Please log in to reply
14 replies to this topic

#1 Reddoug

Reddoug

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 07 December 2013 - 11:16 PM

Hi All

 

So today I went out and bought C Programming Absolute Beginner's Guide (must be a glutton for punishment) and I cannot get might first program to run. I am getting an Syntax error: word unexpected (expecting ")"). I am using Code::Block in Ubuntu. Below is the script. Compiles without any errors.  I have done a buch of searching but haven't come up writh a solution.

 

Thanks, Doug

 

/* Prints a message on the screen*/
#include <stdio.h>
main()
{
    printf ("Just one small step for coders. One giant leap for");
    printf (" programmers!\n");
    return 0;
}
 



BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:04:35 AM

Posted 07 December 2013 - 11:31 PM

The program you posted is completely valid, and produces the output you'd expect. (See IDEOne)

If you're getting syntax errors, they are not in the snippet of code that you posted.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Sirawit

Sirawit

    Bleepin' Brony


  • Malware Response Team
  • 4,161 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Thailand
  • Local time:06:35 PM

Posted 08 December 2013 - 04:46 AM

Billy, he said "Below is the script. Compile without any errors."

Reddoug, what is the code you are getting error?

Thank you.

If I don't reply back to you in 2 days, feel free to send me a PM.

 

“You’re lying… just like you were lying to me before. You have to hate me. I’ve been the worst daughter in the world… you should hate me.”

“But I don’t, Nyx. Because, Nyx, I’m your mother, and a mother will always love her daughter, no matter what.” -Past sins by Pen stroke.


#4 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 08 December 2013 - 07:21 AM

I get    Process returned 2 (0x2) after trying to run the program. In the build log, it  shows    Process terminated with status of 0 (3 minutes, 50 seconds)

 

Thanks, Doug



#5 Sirawit

Sirawit

    Bleepin' Brony


  • Malware Response Team
  • 4,161 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Thailand
  • Local time:06:35 PM

Posted 08 December 2013 - 08:22 AM

Please post your C code you have written, not exit code. And please post your syntax error again.

 

Thank you.


If I don't reply back to you in 2 days, feel free to send me a PM.

 

“You’re lying… just like you were lying to me before. You have to hate me. I’ve been the worst daughter in the world… you should hate me.”

“But I don’t, Nyx. Because, Nyx, I’m your mother, and a mother will always love her daughter, no matter what.” -Past sins by Pen stroke.


#6 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 08 December 2013 - 03:13 PM

Here it is again. 

 

Thanks, Doug

 

/* Prints a message on the screen*/
#include <stdio.h>
main()
{
    printf ("Just one small step for coders. One giant leap for");
    printf (" programmers!\n");
    return 0;
}

Syntax error: word unexpected (expecting ")")



#7 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:04:35 AM

Posted 08 December 2013 - 03:52 PM

Billy, he said "Below is the script. Compile without any errors."


And yet he also said something about a syntax error, which would be an error in the code which causes it not to compile.

Reddoug, there is no syntax error in that code. You need to post the code where the error actually occurs.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#8 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 08 December 2013 - 05:39 PM

Hi

 

I copy and pasted the code from code box. That is what is puzzling me. I got the code from the book I am reading I just tried code below and get the same error. I have noticed that is is trying to run with Xterm. Could that be the problem or is it Code Block is setup?

/* Hello World program */

#include<stdio.h>

main()
{
    printf("Hello World");
}


#9 SillyMuppet

SillyMuppet

  • Members
  • 16 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:35 PM

Posted 11 December 2013 - 03:26 AM

Try:

#include <stdio.h>

int main()
{
    printf ("Just one small step for coders. One giant leap for");
    printf (" programmers!\n");
	
    return 0;
}

That works and compiles fine for me.


Edited by SillyMuppet, 11 December 2013 - 03:43 AM.


#10 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 11 December 2013 - 09:11 PM

I will give a try and see what happens. Updated Virtual Box the other day and now my Linux virtual machines will not start. Get a kernal error failed to load so I will have to figure that out and get back with the results.

 

Thanks, Doug



#11 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 12 December 2013 - 10:09 PM

I ran it today and I got syntax error  Syntax error: "(" unexpected

 

Thanks, Doug



#12 SillyMuppet

SillyMuppet

  • Members
  • 16 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:35 PM

Posted 13 December 2013 - 03:18 AM

Something is definitly off with your compiler then.

 

Are you using gcc?

 

If so try "gcc --version" see what that gives you.

 

If that works fine try making a text file on the desktop named main.c and paste the code from above in there. Save it when done

 

Then open a terminal and type "cd /home/yourusername/Desktop"

Then just type "gcc main.c -o test"

And lastly type ./test

 

If this works then that means it's something with codeblocks itself.



#13 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:06:35 AM

Posted 14 December 2013 - 12:40 PM

Why are using VirtualBox ? You can install CodeBlocks in Windows itself.



#14 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 15 December 2013 - 06:19 PM

I guess I need to try and figure out how to use Code Block. I installed it on Windows today and it will not work properly. When I complied it, it did not do anything and then when I went to run it said it hadn't been built and woould I like to build it now and did not do naything eles. When I have more time I will see what I can figure out. I am going to walk away from it for a while.

 

My last error "Syntax error: "(" unexpected" was running Code Block on a Linux machine, not in Virtual Box.

 

Thanks for the help, Doug



#15 Reddoug

Reddoug
  • Topic Starter

  • Members
  • 115 posts
  • OFFLINE
  •  
  • Local time:06:35 AM

Posted 17 December 2013 - 07:58 PM

Hi

 

Figured out my problem today. When I install Code:Blocks I did not set it to use the right compiler. Programs now run as they should.

 

Thanks again for taking the time to try and help me my problem.

Doug






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users