Unexpected error while running hello world code on vs studio

In summary, the conversation discusses a person's attempt at writing a C program to print "hello world". They mention their lack of experience with programming and their use of different tools, such as a Linux terminal and Visual Studio. The conversation also touches on the error message that the person encountered and suggests using Google or forums like StackOverflow to find solutions. Finally, it is mentioned that the correct way to compile and run a C program is through the use of commands such as "gcc" and "./a.out".
  • #1
randomgamernerd
139
4

Homework Statement

: [/B]Write a C program to print hello world

2. The attempt at a solution:
I am completely new to programming.
I am learning C at present.
In my college, we use linux. Since my pc has windows installed so I am using cygwin terminal to use linux commands from windows.
I am currently using visual studio.
I tried to write the first program hello world.
Capture..JPG

But could not figure out the error.
 

Attachments

  • Capture..JPG
    Capture..JPG
    17.4 KB · Views: 504
Physics news on Phys.org
  • #2
C is a compiled language. You cannot run the source code (file with the .c extension) directly. That file must be compiled into an executable file.
It has been years since I have looked at C though.

I recently took a Python class, and now am working on R for a Micromasters program. One thing that often sheds some light is "Googling the error message".

You should try it. When I did it with your error message, one of the search results that I received, is this StackOverflow post:
https://stackoverflow.com/questions/18450014/syntax-error-near-unexpected-token

In reading this, it reminded me of what is going on. The person asking this question was trying to run the .c file directly, just as you were. It appears that they give the proper steps to take for gcc.
Stackoverflow is a forum, where people ask and answer question specific to programming. Note the date on this post is from 2013, so this type of problem is not a new one.
 
Last edited:
  • #3
When you compile using only
Code:
gcc test.c
then the executable produced is called "a.out".

The command should thus be
Code:
./a.out
not
Code:
./test.c

It would probably be better to compile using
Code:
gcc -o test test.c
to create an executable called "test" instead.
 
  • Like
Likes scottdave

1. What does the error "Unexpected error while running hello world code on vs studio" mean?

The error means that there was an unexpected issue while trying to run the "hello world" code in Visual Studio. This could be due to a variety of reasons, such as a coding error, a problem with the software, or a compatibility issue.

2. How do I fix the "Unexpected error while running hello world code on vs studio" error?

The best way to fix this error is to carefully review your code and check for any errors. If you are unable to find any issues with your code, try restarting Visual Studio or updating to the latest version. It may also be helpful to search online for solutions or ask for assistance from other programmers.

3. Can a computer virus cause the "Unexpected error while running hello world code on vs studio" error?

In rare cases, a computer virus could potentially cause this error if it has infected the Visual Studio software or the code itself. However, it is more likely that the error is caused by a coding issue or software problem.

4. Does the "Unexpected error while running hello world code on vs studio" error occur frequently?

No, this error does not occur frequently. It is more common for errors to occur while coding more complex programs or when using unfamiliar software. However, if you encounter this error frequently, it may be a sign of a larger issue with your computer or software.

5. Is there a way to prevent the "Unexpected error while running hello world code on vs studio" error from happening?

While it is impossible to completely prevent errors from occurring while coding, there are steps you can take to minimize the chances of encountering this error. These include regularly checking your code for errors, keeping your software up to date, and ensuring that your computer is running smoothly. It may also be helpful to have a backup plan in case an error does occur, such as saving your code frequently or using a different coding platform.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Programming and Computer Science
Replies
1
Views
507
  • Programming and Computer Science
Replies
2
Views
305
Replies
3
Views
327
  • Programming and Computer Science
Replies
2
Views
854
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
1
Views
257
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Replies
15
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Back
Top