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 01-15-2019, 02:25 AM   #1
abhishek98
LQ Newbie
 
Registered: Jan 2019
Posts: 2

Rep: Reputation: Disabled
coding in c problem occuring


#include <stdio.h>
int main()
{
int A, B, C;

printf("Enter three numbers: ");
scanf("%d %d %d", &A, &B, &C);

if (A >= B) {
if (A >= C)
printf("%d is the largest number.", A);
else
printf("%d is the largest number.", C);
}
else {
if (B >= C)
printf("%d is the largest number.", B);
else
printf("%d is the largest number.", C);
}

return 0;
}
run time error
solution.sh: line 5: syntax error near unexpected token `"Enter three numbers: "'
solution.sh: line 5: ` printf("Enter three numbers: ");
 
Old 01-15-2019, 02:27 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,995

Rep: Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097
what is solution.sh? What you posted is a c file, you need to compile and execute it. It is not a shell script.
 
2 members found this post helpful.
Old 01-15-2019, 02:31 AM   #3
abhishek98
LQ Newbie
 
Registered: Jan 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
i am new in programming so during running this code the error is occuring
solution.sh: line 5: syntax error near unexpected token `"Enter three numbers: "'
solution.sh: line 5: ` printf("Enter three numbers: ");
what is meaning of this error
i am not getting
 
Old 01-15-2019, 04:01 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,995

Rep: Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097Reputation: 4097
http://www.catb.org/esr/faqs/smart-q...html#beprecise
 
1 members found this post helpful.
Old 01-15-2019, 04:21 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 18,924

Rep: Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850Reputation: 2850
As posted c programs have to be complied before they can be executed.

gcc -o my_program my_program.c
./my_program
 
1 members found this post helpful.
Old 01-15-2019, 06:50 PM   #6
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,283

Rep: Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858Reputation: 858
Quote:
Originally Posted by abhishek98 View Post
i am new in programming so during running this code the error is occuring
solution.sh: line 5: syntax error near unexpected token `"Enter three numbers: "'
solution.sh: line 5: ` printf("Enter three numbers: ");
what is meaning of this error
i am not getting
It means that the file solution.sh has a syntax error in line 5.

What you posted is a C program. The shell can't interpret C programs.

Try this:
Code:
cp solution.sh solution.c
make solution
./solution
The first line copies your program into a file named solution.c. The second line invokes the compiler and linker to generate an executable program from your C code. The third line runs that program. If there is an error in your program, either the second or the third line will fail with a (hopefully) meaningful error message.

It could be that the make command is not found. This means that your computer lacks a program development environment. To help you install it, you need to tell us which operating system you are running.

Last edited by berndbausch; 01-15-2019 at 06:52 PM.
 
1 members found this post helpful.
Old 01-16-2019, 04:46 PM   #7
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,532

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
deleted.

Last edited by JeremyBoden; 01-16-2019 at 04:52 PM.
 
Old 01-18-2019, 12:22 AM   #8
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 341

Rep: Reputation: 99
Quote:
Try this:

cp solution.sh solution.c
.....

The first line copies your program into a file named solution.c.
The file should just be renamed with mv and not copied. There is no need to have a file named 'solution.sh' as this isn't a shell script.

It should be
mv solution.sh solution.c

Last edited by tofino_surfer; 01-18-2019 at 10:55 AM.
 
  


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
cursor 'ghosts' occuring greengrocer Linux - Newbie 13 07-24-2006 08:18 PM
Monitor problem still occuring rmckayfleming Linux - Hardware 1 10-15-2005 10:04 AM
various LPD errors occuring on RH8.0 fishsponge Linux - General 4 07-08-2005 04:34 AM
Odd hardware problem occuring in linux and windows. RoaCh Of DisCor Linux - Hardware 7 04-18-2005 05:59 PM
Re-occuring ATI driver install problem Gamezace Linux - Hardware 7 02-11-2005 12:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:23 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