473,503 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

confused..again

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

Dec 30 '07 #1
24 1743
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
es*****@ieee-dot-org.invalid
Dec 30 '07 #2
In article <s9Tdj.35028$NL5.2831@trnddc05>,
Bill Cunningham <no****@nspam.comwrote:
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
Dec 30 '07 #3

"Bill Cunningham" <no****@nspam.comschreef 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?

Dec 30 '07 #4
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
Dec 30 '07 #5

"Eric Sosman" <es*****@ieee-dot-org.invalidwrote in message
news:od******************************@comcast.com. ..
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

Dec 30 '07 #6
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
Dec 30 '07 #7
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
Dec 30 '07 #8
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.

Dec 31 '07 #9
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.

Dec 31 '07 #10

"Mark McIntyre" <ma**********@spamcop.netwrote in message
news:rY*******************@newsfe2-gui.ntli.net...
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.
Thanks Mark.

Bill
Dec 31 '07 #11

"Mark McIntyre" <ma**********@spamcop.netwrote in message
news:SZ******************@newsfe2-gui.ntli.net...
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.
Yes and the medications I'm on don't help that problem.

Bill
Dec 31 '07 #12
On Sun, 30 Dec 2007 18:46:42 -0600, Mark McIntyre wrote
(in article <SZ******************@newsfe2-gui.ntli.net>):
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.
He could read the google archives for the old answers to his old
questions.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 31 '07 #13

"Bill Cunningham" <no****@nspam.comschreef in bericht
news:noXdj.4136$ZI4.2742@trnddc08...
>
"Mark McIntyre" <ma**********@spamcop.netwrote in message
news:SZ******************@newsfe2-gui.ntli.net...
>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.

Yes and the medications I'm on don't help that problem.
No offense meant, but wouldnt it be better to have another hobby where
medication etc does not get in your way? Surely there are more satisfying
things in life than learning something for years without success

Dec 31 '07 #14
Bill Cunningham wrote:
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()?
I have been away from C for over a year. Now I'm trying to give it
a go again and studying again.
That didn't answer the question. What book are you using that doesn't
show the printf() modifiers for strings?


Brian
Dec 31 '07 #15
Mark McIntyre wrote:
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.

Dec 31 '07 #16
Mark McIntyre wrote:
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.

Regardless of difficulties, if he has a reference book and can't follow
simple directions like using the correct printf() modifiers, then he's
wasting his time and ours.

If he's not using a book, then he's REALLY wasting time. Hence my
question.

Brian
Dec 31 '07 #17
On Mon, 31 Dec 2007 17:04:02 +0100, Serve Lau wrote:
> Yes and the medications I'm on don't help that problem.

No offense meant, but wouldnt it be better to have another hobby where
medication etc does not get in your way?
"Herr Beethoven, with your condition I suggest you give up music".

In other words, if people didn't struggle against difficult problems,
there would be little progress...
Surely there are more
satisfying things in life than learning something for years without
success
Ask the England cricket team.... :-)
Dec 31 '07 #18
On Mon, 31 Dec 2007 18:42:29 +0000, Default User wrote:
Regardless of difficulties, if he has a reference book and can't follow
simple directions like using the correct printf() modifiers, then he's
wasting his time and ours.
Its pretty obvious that few of us work in special needs teaching, isn't
it?

Dec 31 '07 #19
On Mon, 31 Dec 2007 17:16:25 -0600, Mark McIntyre wrote
(in article <dL*******************@newsfe1-gui.ntli.net>):
On Mon, 31 Dec 2007 18:42:29 +0000, Default User wrote:
>Regardless of difficulties, if he has a reference book and can't follow
simple directions like using the correct printf() modifiers, then he's
wasting his time and ours.

Its pretty obvious that few of us work in special needs teaching, isn't
it?
It's at least clear that some haven't felt compelled to allow political
correctness concerns to alter reality yet.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 31 '07 #20

"Mark McIntyre" <ma**********@spamcop.netwrote in message
news:rY*******************@newsfe2-gui.ntli.net...
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.
Mark,

I haven't got to the functions used in the string.h header yet. The tutorial
at
http://www.eskimo.com/~scs/cclass/

has helped me more than any other. You pick up little things like int c is
not as good as int c=0 because int c is bound to contain garbage if not
initialized to something. That's better than just references functions from
a book you really haven't studied yet. I have been away from C for around a
year.

This is how I tried to use the function.
int c=0;
c=strcmp(name,name2);

Like I say I will have to probably come to this function in the turtorial I
don't want to ask someone to do my homework for me but what good is a C
community if you don't participate. Aspiring amateur programmers probably
I'm sure get on the nerves of professionals. I need to know how to use this
with if ().
I have major depression and panic attacks to the point of convulsive
problems and being drawn up in the floor.
This hinders concentration, retention, and attention. Klonopin has an affect
of confusing its patient.
Bill

Jan 1 '08 #21
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
Works fine when you correct the code:

#include <stdio.h>

int main(void) {
char name[200];

printf("Enter -");
fflush(stdout);
fgets(name, 200, stdin);
printf("is %s\n", name);
return 0;
}

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Jan 1 '08 #22
Bill Cunningham wrote, On 01/01/08 00:16:
"Mark McIntyre" <ma**********@spamcop.netwrote in message
news:rY*******************@newsfe2-gui.ntli.net...
>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.

Mark,

I haven't got to the functions used in the string.h header yet. The tutorial
at
http://www.eskimo.com/~scs/cclass/

has helped me more than any other. You pick up little things like int c is
That is one of the few good online tutorials from what I hear.
not as good as int c=0 because int c is bound to contain garbage if not
initialized to something. That's better than just references functions from
a book you really haven't studied yet. I have been away from C for around a
year.

This is how I tried to use the function.
int c=0;
c=strcmp(name,name2);
The normal way to use strcmp is
if (strcmp(s1,s2)==0) {
/* strings are the same */
}
else {
/* strings are different */
}
Like I say I will have to probably come to this function in the turtorial I
don't want to ask someone to do my homework for me but what good is a C
community if you don't participate. Aspiring amateur programmers probably
I'm sure get on the nerves of professionals. I need to know how to use this
with if ().
People find you frustrating because you have been trying off and on for
a long time and are still at an early stage. People who find you
annoying should just killfile you and leave it to people with more patience.
I have major depression and panic attacks to the point of convulsive
You have problems which is why some people cut you a lot of slack. The
problems *might* make it impractical for you to learn C, but however
well you do that you are trying to do something constructive is good.
However, this is not a support group, so don't expect most people to
understand your problems or be supportive of them.
--
Flash Gordon
Jan 1 '08 #23
Mark McIntyre wrote:
On Mon, 31 Dec 2007 18:42:29 +0000, Default User wrote:
Regardless of difficulties, if he has a reference book and can't
follow simple directions like using the correct printf() modifiers,
then he's wasting his time and ours.

Its pretty obvious that few of us work in special needs teaching,
isn't it?
Part of that is facing reality. If he can't follow the book to that
level after months of trying, he will never be a C programmer. He
should move to something else. As I said, wasting his time and ours.

Brian
Jan 1 '08 #24
Mark McIntyre <ma**********@spamcop.netwrote:
On Mon, 31 Dec 2007 17:04:02 +0100, Serve Lau wrote:
Yes and the medications I'm on don't help that problem.
No offense meant, but wouldnt it be better to have another hobby where
medication etc does not get in your way?

"Herr Beethoven, with your condition I suggest you give up music".
Herr Van Beethoven did not start out deaf before he learned to compose.
Surely there are more satisfying things in life than learning something
for years without success

Ask the England cricket team.... :-)
Says the citizen of the one country whose cricket team managed to get
beaten by ours...

Richard
Jan 2 '08 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2603
by: Brian Roberts | last post by:
I'm confused about the use of hasattr/getattr, or possibly namespaces. I know how to do this: class UnderstandThis(object): def do_foo(self): pass def do_bar(self): pass def doit(self, cmd):...
45
2527
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently...
11
4894
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
2
2108
by: jh8735 | last post by:
I use Access to run reports from various pieces of financial data. The one query that I have been unable to produce, but need is the following: A query that yields all accounts from a person...
2
1680
by: Kevin C. | last post by:
Can someone explain why the file output produces all zeros? It seems to work fine in memory (e.g. passing char pointers to printf) but when I output the file, it comes out as zeros. Bookkeeping...
9
2214
by: vijay | last post by:
Hello, I am new to C Programming and just started reading K&R. I was about to finish the pointers chapter but got very confused with: 1. int arr; >From what I have read, arr is a pointer to...
6
1950
by: Louise | last post by:
I use Visual Basic .NET Framework 1.1, Visual Studio. I have a Web page (aspx) referencing a control (ascx) that has a placeholder that is assigned one of 2 child controls through buttons. The...
2
1045
by: Moe | last post by:
Hello, I am very confused. Here is my situation: I have a web form with a few fields in place that are used as search criteria for a SQL database. Since I want the search criteria to be...
3
1163
by: C CORDON | last post by:
I am verry confused about classes. I understand that classes can encapsulate properties, methods, events (don't know hoy to add events to a class), etc. I am confused with this: if you can...
20
1787
by: mechanicfem | last post by:
I thought (as they're in c99) that flexible arrays were there for a number of reasons - but I also thought they'd be great for stepping into structures (say) that were aligned in memory after (say)...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.