confused..again

B

Bill Cunningham

Mark McIntyre said:
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
 
C

CBFalconer

Bill said:
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;
}
 
F

Flash Gordon

Bill Cunningham wrote, On 01/01/08 00:16:
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.
 
D

Default User

Mark said:
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
 
A

Army1987

Bill said:
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.
If you are going to assign to c the first time you use it, what it
contains before is totally irrelevant.
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.
Why? If you need to use a function, just read its documentation and use it.
This is how I tried to use the function.
int c=0;
c=strcmp(name,name2);
That's unnecessary. Just use
if (strcmp(name, name2) == 0) {
printf("ok\n");
} else {
printf("Sorry, try again.\n");
return main();
}
Note that I added a newline at the end of the output. Implementations
aren't required to allow you to have partial lines at the end of a text
file, including stdout; and, on the ones which do, it can be a good idea,
e.g. it could cause the shell prompt to be on the same line as the
program's output.
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.
I hope you get better.
 
R

Richard Bos

Mark McIntyre said:
"Herr Beethoven, with your condition I suggest you give up music".

Herr Van Beethoven did not start out deaf before he learned to compose.
Ask the England cricket team.... :)

Says the citizen of the one country whose cricket team managed to get
beaten by ours...

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top