#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    1
    Rep Power
    0

    Very simple strig program. NEED HELP


    Hello everyone, I want to ask your advice...
    I im facing with problem when i try to do this program.
    Code:
    #include <cstdio>
    #include <stdio.h>
    #include <ctype.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define MAX 1000
    
    int main()
    {
        float sk;
        char zodis[MAX];
        FILE *fr = fopen("u2-input.txt", "r");
    
        printf("write the number:");
        scanf("%f", &sk);
    
        while(!feof(fr))
        {
            fscanf(fr," %s ", &zodis);
            if (isdigit(zodis) && zodis<sk)
            {
            printf("%s \n", zodis);
            }
        }
    
        return 0;
    }
    This program should find numbers from text which is smaller than number sk.

    How i need to fix it?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,367
    Rep Power
    1870
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    if (isdigit(zodis) && zodis<sk)

    isdigit expects a single character. zodis is not a single character, though zodis[0] would be. zodis is a pointer, the address of the char array zodis. I doubt very much that the memory address of zodis would be between the int values of 0x30 through 0x39, since that would place the array way down at the beginning of memory which I assume is still where the operating system's Interrupt Vector Table resides. Rather zodis' memory address is a value that is much greater -- much greater even than any value in the ASCII table.

    BTW, I'm sure your compiler would have thrown warnings at you about trying to pass a char pointer to a function that expects an int -- different levels of indirection, unable to convert that, etc. Assuming that you enabled warnings and were merely willfully ignoring warnings!

    Always turn warnings on and up! Never ignore warnings!
    Last edited by dwise1_aol; October 23rd, 2013 at 02:17 PM.

IMN logo majestic logo threadwatch logo seochat tools logo