Thread: need help..quickly

  1. #16
    Registered User
    Join Date
    May 2003
    Posts
    1
    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

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    16
    Code:
    #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;
    }
    hey u r right aaron...Im gonna try that when I get back to school...thanks

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >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:
    Code:
    if (strcmp(day,"monday") == 0)
    Since the implicit test is
    Code:
    if (strcmp(day,"monday") != 0)
    you may not be getting what you expect.
    My best code is written with the delete key.

  4. #19
    Registered User
    Join Date
    Apr 2003
    Posts
    16
    I have
    if (str(day,"monday")==0)
    {
    intday = 1;
    }

    help please

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by digy
    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:

    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.

  6. #21
    Registered User
    Join Date
    Apr 2003
    Posts
    16
    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.

  7. #22
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    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.

    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.

  8. #23
    Registered User
    Join Date
    Apr 2003
    Posts
    16
    well then refuse to help me....

    sorry if I appear stupid to you

  9. #24
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    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

  10. #25
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >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.

  11. #26
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    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.
    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.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quickly learn C# for a C++ expert
    By BigDaddyDrew in forum C# Programming
    Replies: 9
    Last Post: 06-06-2004, 04:38 PM
  2. How can I initiate my growth of beard more quickly?
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 07-21-2003, 05:15 PM
  3. console.. character.. screen.. quickly!
    By CodeMonkey in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2003, 06:00 PM
  4. I need excuses for school dance! -- quickly!
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 01-21-2003, 04:42 AM
  5. Reading from a file quickly
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-11-2002, 01:12 PM