1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

sscanf()-getting integer from a string

Discussion in 'C' started by saman_glorious, Sep 2, 2010.

  1. saman_glorious

    saman_glorious New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I want to extract the integer value form my file name, and there's no space between my file name
    like Quote:
    part1.dat or part12.dat
    Code:
    char src[20] = "part12.dat";
    char dest[10];
    int *i;

    sscanf(src, "%[1-9]", &i);
    printf("%d", *i);
    could u plz correct my formatted text
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    Please refer to the following code...u will be able to undertand the mistake urself...always try to check the syntax of a function before using it....
    Code:
    const char * str = "part346.dat";
    int value;
    
    sscanf(str,"%*[^0-9]%d",&value);
    printf("%d",value);
    
     

Share This Page