Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 MinGW is a C and C++ compiler. Get Dev-C++, it comes with MinGW and has a much better interface. Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 (edited) Anybody want to give me a challenge? to make a program to do something. BTW I AM A MAJOR NOOB! I STARTED LEARNING C TODAY! I KNEW NOT ONE SINGLE THING ABOUT IT BEFORE TODAY. so give me a program to make. Edited August 4, 2005 by Blue_cow Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) Have the user enter a sentence and then redisplay it. That'll test your usage of variables, arrays, and the printf() and scanf() functions. Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 (edited) Heres what ive got so far but im kindof stuck... #include <stdio.h> int main () { char sentance; printf ("Please enter a sentance:"); scanf ( "%s", &sentance ); printf ("You typed: %c\n", sentance); return 0; } EDIT: Ok, i got it working past debug mode but when it asks to enter a sentance, you do, and when you press enter it closes... :/ Edited August 4, 2005 by Blue_cow Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted August 4, 2005 Posted August 4, 2005 Heres what ive got so far but im kindof stuck... #include <stdio.h> int main () { char sentance; printf ("Please enter a sentance:"); scanf ( "%s", &sentance ); printf ("You typed: %c\n", sentance); return 0; } EDIT: Ok, i got it working past debug mode but when it asks to enter a sentance, you do, and when you press enter it closes... :/ 522317[/snapback] Try system("pause"); at the end Like... printf ("You typed: %c\n", sentance); system("pause"); return 0; } I think you may have to include "stdlib.h" too, so up where it says #include <stdio.h> add another line: #include <stdlib.h> Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) Also, try using a char array if you want more then one letter. Or, if you're lazy: typedef char[] string Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted August 4, 2005 Posted August 4, 2005 Also, try using a char array if you want more then one letter. Or, if you're lazy: typedef char[] string 522404[/snapback] Well picked up on! Buuut your solution doesn't solve the problem, nor does it actually work char sentance[500]; Should suffice for something basic, just so long as you don't go over 500 characters on your input! Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 What did I do wrong now? Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 (edited) You two are like a married couple. Thanks for the help guys! Ill see if it works. Edit: here's what i have, and it doesnt work. #include <stdio.h> #include <stdlib.h> int main () { char sentance[500]; printf ("Please enter a sentance:"); scanf ("%s", &sentance ); printf ("You typed: %c\n", sentance); system("pause"); return 0; } It compiles with no bugs, but when you enter in a senctence (eg. This is a senctence) it will come back with: You typed: p. Every time. So... yeeeahh. Edited August 4, 2005 by Blue_cow Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted August 4, 2005 Posted August 4, 2005 You two are like a married couple. Thanks for the help guys! Ill see if it works. Edit: here's what i have, and it doesnt work. #include <stdio.h> #include <stdlib.h> int main () { char sentance[500]; printf ("Please enter a sentance:"); scanf ("%s", &sentance ); printf ("You typed: %c\n", sentance); system("pause"); return 0; } It compiles with no bugs, but when you enter in a senctence (eg. This is a senctence) it will come back with: You typed: p. Every time. So... yeeeahh. 522447[/snapback] eek, missing a lot today! Simple error... printf ("You typed: %c\n", sentance); Change %c (which prints out only one character) tooo %s. printf ("You typed: %s\n", sentance); aaaaand KB: Did you try and use that typedef yourself? AFAIK [] is just a friendly was of saying it's a pointer. I could be wrong there so feel free to look it up! (I am kinda busy). Buuut arrays have to be after a variable name it seems, so using it in a typedef wouldn't work..? Even if it did work - assuming it is just a friendly way of saying "I'm a pointer" - instead of having storage space for one char you've got a pointer to some random place in memory, and the sentance would be stored.... *somewhere*. It *may* well work and not crash, but you'll have unpredictable results by overwriting random memory I think Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) Lol, I'm monogamous and have myself a significant other already. Markie can wait . EDIT: Markie, you posted at the same dang time as me. Lemme put some more in... EDIT2: dang, I was always told that char[] daArrayz0rz = "Da arrayz0rz!" would tell the compiler to fill in the blank itself... dang... Would this work? typdef char string [1024] Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 [quote name=markiemrboo' date='Aug 4 2005, 12:55 PM printf ("You typed: %c\n", sentance); Change %c (which prints out only one character) tooo %s. printf ("You typed: %s\n", sentance); 522452[/snapback] BAHH!!!! How did i miss that! Ok so (sorry if it feels like you guys are walking me through it, i think im maknig a bit of progress.) now it works except that the output is only one word. Do i need to have more scanfs and/or variables? Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now