Bare with me, i'm new at this also. but i remember reading something about scanf and strings.
scanf("%s%d",&day,&num);
day should not be preceded by the ampersand since it is a string.
scanf("%s%d",day,&num);
Aaron
Bare with me, i'm new at this also. but i remember reading something about scanf and strings.
scanf("%s%d",&day,&num);
day should not be preceded by the ampersand since it is a string.
scanf("%s%d",day,&num);
Aaron
hey u r right aaron...Im gonna try that when I get back to school...thanksCode:#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int intDay; int num; int newday; char day[10]; clrscr(); printf("Enter a day of the week and number of days between 1000 and 10000:\n"); scanf("%s%d",&day,&num); newday = num % 7; printf("newday: %d\n",newday); if (strcmp(day,"monday")) { intday = 0; printf("The day is a Monday"); } else if (strcmp(day,"tuesday")) { intday = 1; printf("The day is a Tuesday"); } else if (strcmp(day,"wednesday")) { intday = 2; printf("The day is a Wednesday"); } else if (strcmp(day,"thursday")) { intday = 3; printf("The day is a Thursday"); } else if (strcmp(day,"friday")) { intday = 4; printf("The day is a Friday"); } else if (strcmp(day,"saturday")) { intday = 5; printf("The day is a Saturday"); } else if (strcmp(day,"sunday")) { intday = 6; printf("The day is a Sunday"); } else { printf("Incorrect Input"); } return 0; }
>int intDay;
You declare intDay but use intday, one of these needs to be changed to match the other.
>scanf("%s%d",&day,&num);
The & isn't needed on a pointer.
>if (strcmp(day,"monday"))
Are you testing for equality or inequality? A test for equality should compare against 0:
Since the implicit test isCode:if (strcmp(day,"monday") == 0)
you may not be getting what you expect.Code:if (strcmp(day,"monday") != 0)
My best code is written with the delete key.
I have
if (str(day,"monday")==0)
{
intday = 1;
}
help please
How about you pay attention? It isn't "str", it's "strcmp". If you paid attention to the error your compiler spits at you, you'd see the problem. And one more time:Originally posted by digy
I have
if (str(day,"monday")==0)
{
intday = 1;
}
help please
strcmp( a, b ) == 0 is testing for an exact match
strcmp( a, b ) != 0 is testing for a non-match
Quzah.
Hope is the first step on the road to disappointment.
HEY this post is supposed to be for helping ppl who are learning "C"...remember???
if you don't want to help then stay off.
I wrote it out wrong...thats all.
Well maybe if you actually paid attention, you'd have your answer. No thread should be this long. Any questions should easily be understood long before the post hits the two page mark.Originally posted by digy
HEY this post is supposed to be for helping ppl who are learning "C"...remember???
if you don't want to help then stay off.
I wrote it out wrong...thats all.
1) Post your code.
2) Use code tags when you post your code.
3) Explain in detail what the program is supposed to do.
4) Explain in detail what the program does do that it shouldn't be doing.
5) Explain in detail what the program doesn't do that it should do.
6) Explain exactly how far the program gets. (Does it compile? Does it run?)
7) List in detail what errors and warnings you get when you compile, if any.
I have no problems helping people. I refuse to help people who don't pay attention and refuse to learn from the help they have been given. You have already been given your answer. Use it.
Quzah.
Hope is the first step on the road to disappointment.
well then refuse to help me....
sorry if I appear stupid to you
Rather than working on the entire program at once, work on small sections with test progs. Set up a small program to input your string, and then try your strcmp function on just that input. Once you get that worked out, move to the number, and so on
List the expected output for a small range of input values.
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
>well then refuse to help me....
You've had sufficient help to solve your problem. We won't write your program for you.
I'll also direct you here concerning quzah. When other regular members feel someone is being exceptionally abusive they will react. If there's no reaction then acting insulted and childish is a bad idea. If that's too suble, I'll spell it out: quzah is right, you are wrong. Read what he tells you and learn from it.
My best code is written with the delete key.
Thanks for that link, Prelude. I now have a better insight in "community of hackers" and forum decorum. I've been in computers for ages but am new to boards of this kind. A very helpful page.Originally posted by Prelude
I'll also direct you here concerning quzah. When other regular members feel someone is being exceptionally abusive they will react.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers