Why cant i get this code to work?
Code:#include <stdio.h> int main() { char work; printf("Hello, does this program work?\n"); work=getchar(); if (work != 'yes') printf("That's too bad... ;)\n"); else printf("Works! :D"); system ("PAUSE"); }
Why cant i get this code to work?
Code:#include <stdio.h> int main() { char work; printf("Hello, does this program work?\n"); work=getchar(); if (work != 'yes') printf("That's too bad... ;)\n"); else printf("Works! :D"); system ("PAUSE"); }
because 'yes' is not one char
work can store only 1 char 'y' for example...
Havn't you got any warnings from the compiler?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
It never ceases to amaze me how people can make a mess of indenting even the shortest of programs
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
So what should i use instead of "char"?
It depends on what do you want to achieve. Describe your goal.Originally Posted by Denisius
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
My guess is he'd want to use a char* and replace getchar() with fgets...
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
It's ok, i solved the problem.
And dont use
use getchar()Code:system ("PAUSE");
ssharish2005
Why should'nt i use?Code:system ("PAUSE");
I it not portable.Originally Posted by Denisius
You have a portable solution that does the same. So why bother with the SYSTEM?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Also is insecure. Someone might feel like adding a pause.exe file to your folder which wipes out your hard drive. your system("pause") call will then execute this file instead of the pause command.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.