Jump to content
Sign in to follow this  
Blue_cow

Looking To Learn Something

Recommended Posts

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 by Blue_cow

Share this post


Link to post
Share on other sites

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites

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 by Blue_cow

Share this post


Link to post
Share on other sites
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
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

:rolleyes: 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 by Blue_cow

Share this post


Link to post
Share on other sites
:rolleyes: 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]

 

:lol: 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 :P

 

I think :)

Share this post


Link to post
Share on other sites

Lol, I'm monogamous and have myself a significant other already. Markie can wait :D.

 

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites

[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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×