ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Location: Rome, Italy ; Novi Sad, Srbija; Brisbane, Australia
Distribution: Ubuntu / ITOS2008
Posts: 1,207
Rep:
Dumb.. but i cant figure it out.
Im learning C form some cheap book, and writing short programs just to see if i understood how the command works.
Well here is a simple program that won't compile:
# include <stdio.h>
main ()
{
char ans;
/* Get correct input fromn the user, loop until the input is correct (y or n) */
do {
printf ("Is your printer turned ON? ( 'y' or 'n' )");
scanf (" %c", ans);
while ((ans != 'y') && (ans != 'n'));
}
/* Use a conditional to tell waht is happening once the correct input was entered */
/* line18 */ (ans == 'y') ? (printf ("I will start printing now.\n")) : (printf ("Turn on the printer and run the program again please.\n"));
return 0;
}
Here is the output from the compiler:
--(Sat Nov 9, 16:56:55)--(nskl@SlackBox:~/programming)$ gcc -o dowhile dowhile.c
dowhile.c: In function `main':
dowhile.c:18: parse error before `('
--(Sat Nov 9, 16:57:04)--(nskl@SlackBox:~/programming)$
I'm thinking it must be something simple... But i tried rewriting the program, changing it around, even using two if statements instead of the conditional, but i can't get it to work. Can anyone point me to waht is wrong here??
Thank you
-NSKL
I haven't looked at it all but let me give you one that stands out. Then see how you go from there. look at the location of your while in relation to your do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.