Thread: strspn()

  1. #1
    JDMac
    Guest

    strspn()

    I want to use strspn() to check that the user input is correct.

    I have never used strspn() before how does it work with my line of codes?

    printf("Enter a number: ");
    scanf("%lf",&number);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: strspn()

    Originally posted by JDMac
    I want to use strspn() to check that the user input is correct.

    I have never used strspn() before how does it work with my line of codes?

    printf("Enter a number: ");
    scanf("%lf",&number);
    Well, gee, if you'd actually have used the function in question, then possibly we could let you know if you used it correctly. As is, who knows what you're trying to do here. You weren't exactly clear on your intent. Perhaps you should read up on the function in question.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    JDMac
    Guest
    I want to make sure that the user entered only numbers.

    I know that there is a better way of doing it..but I have to use strspn() for this problem.

    printf("Enter a number: ");
    scanf("%lf",&number);

    result=strspn(number,"abcdefg");
    puts(result);

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you're supposed to use strspn, then don't use scanf to read into an integer. From the sounds of it, you should be reading into an array, and pass that to strspn to have strspn check it for non-numeric numbers.

    From the above pharagraph, this should be trivial for you, so I'm not going to tell you how to do it.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    JDMac
    Guest
    Thanks.....I know how to take it from here....I tryed it and now it works......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in validation
    By dholman in forum C Programming
    Replies: 2
    Last Post: 01-08-2004, 09:27 AM