Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > confused..again

Reply
Thread Tools

confused..again

 
 
Bill Cunningham
Guest
Posts: n/a
 
      12-30-2007
It is very easy to see what I am trying to do with this code:

#include <stdio.h>

main(){
char name[200];
printf ("Enter -> ");
fflush (stdout);
fgets (name,200,stdin);
printf("is? ",name);}

I have also tried this with the last line with printf

printf("is? %c",name);

Either way same results. Printf will not print the value of name.

Bill



 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      12-30-2007
Bill Cunningham wrote:
> It is very easy to see what I am trying to do with this code:


I'm not finding it easy. Please don't assume everyone
else is as perceptive as you are.

> #include <stdio.h>
>
> main(){
> char name[200];
> printf ("Enter -> ");
> fflush (stdout);
> fgets (name,200,stdin);
> printf("is? ",name);}
>
> I have also tried this with the last line with printf
>
> printf("is? %c",name);
>
> Either way same results. Printf will not print the value of name.


Perhaps you want

printf ("is ? %s", name);

--
Eric Sosman
lid
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      12-30-2007
In article <s9Tdj.35028$NL5.2831@trnddc05>,
Bill Cunningham <> wrote:
> It is very easy to see what I am trying to do with this code:


>#include <stdio.h>


>main(){
> char name[200];
> printf ("Enter -> ");
> fflush (stdout);
> fgets (name,200,stdin);
> printf("is? ",name);}


>I have also tried this with the last line with printf


>printf("is? %c",name);


>Either way same results. Printf will not print the value of name.


printf("is? %s", name);
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
 
Reply With Quote
 
Serve Lau
Guest
Posts: n/a
 
      12-30-2007

"Bill Cunningham" <> schreef in bericht
news:s9Tdj.35028$NL5.2831@trnddc05...
> It is very easy to see what I am trying to do with this code:
>
> #include <stdio.h>
>
> main(){
> char name[200];
> printf ("Enter -> ");
> fflush (stdout);
> fgets (name,200,stdin);
> printf("is? ",name);}
>
> I have also tried this with the last line with printf
>
> printf("is? %c",name);
>
> Either way same results. Printf will not print the value of name.


Strange, I remember somebody years ago with the same name asking these same
kind of newbie questions.

Here, from 2003
http://groups.google.com/group/comp....34df188f17ad68

complete list:
http://groups.google.com/groups?q=gr...&as_maxy=2007&

a troll whose humour I dont understand or what is this?

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      12-30-2007
Bill Cunningham wrote:

> It is very easy to see what I am trying to do with this code:
>
> #include <stdio.h>
>
> main(){
> char name[200];
> printf ("Enter -> ");
> fflush (stdout);
> fgets (name,200,stdin);
> printf("is? ",name);}
>
> I have also tried this with the last line with printf
>
> printf("is? %c",name);
>
> Either way same results. Printf will not print the value of name.


You've supposedly been learning C for months if not years. What book
are you using that doesn't give the procedure for printing strings with
printf()?





Brian
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      12-30-2007

"Eric Sosman" <> wrote in message
news. ..
> Bill Cunningham wrote:
>> It is very easy to see what I am trying to do with this code:

>
> I'm not finding it easy. Please don't assume everyone
> else is as perceptive as you are.
>
>> #include <stdio.h>
>>
>> main(){
>> char name[200];
>> printf ("Enter -> ");
>> fflush (stdout);
>> fgets (name,200,stdin);
>> printf("is? ",name);}
>>
>> I have also tried this with the last line with printf
>>
>> printf("is? %c",name);
>>
>> Either way same results. Printf will not print the value of name.

>
> Perhaps you want
>
> printf ("is ? %s", name);
>

Yes minor stumbling block.
#include <stdio.h>

main(){
char name[200];
char name2[200];
printf ("Enter -> ");
fflush (stdout);
fgets (name,200,stdin);
printf("is? %s",name);
printf("what you mean? Try again.");
fflush(stdout);
fgets(name2,200,stdin);
if (name==name2) {printf("ok");}
else if (name!=name2){
printf("Sorry try again.");
return main();}
return 0;}

THanks now there seems to be an error with if here somewhere. I will try to
figure it out if not I would appreciate a look over.

Bill



 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      12-30-2007
> You've supposedly been learning C for months if not years. What book
> are you using that doesn't give the procedure for printing strings with
> printf()?
>
>
>
>
>
> Brian


I have been away from C for over a year. Now I'm trying to give it a go
again and studying again.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      12-30-2007
> THanks now there seems to be an error with if here somewhere. I will try
> to figure it out if not I would appreciate a look over.
>
> Bill


OK I got it. Don't use else here.

Bill


 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      12-31-2007
On Sun, 30 Dec 2007 23:14:03 +0000, Bill Cunningham wrote:

> if (name==name2) {printf("ok");}


You can't compare strings with ==
The code above compares the addresses of name and name2, to see if
they're equal (which, obviously, they aren't).

You must use strcmp or one of its fellows.

 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      12-31-2007
On Sun, 30 Dec 2007 21:37:04 +0000, Default User wrote:

> You've supposedly been learning C for months if not years.


My recollection is that the OP stated he has learning difficulties.
Provided he doesn't start trolling, I suggest slack is cut.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments