Thread: converting string to integer, for further use

  1. #1
    Registered User
    Join Date
    Jun 2005

    converting string to integer, for further use

    before you flame me, ive tried both strtol AND atoi and they dont work.

    im trying to convert a string to and intger. when i display the string on screen, it is perfect (122). but when i make a folder with the contents of this string, it comes out really wierd.

    i tried strtol and atoi but it doesnt make a difference.

    my attempt:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <windows.h>
    char streaminput[BUFSIZ] = "#RAWWAASFRAMEA,COM1,9,68.0,SATTIME,1263,126458.000,00000000,58e4,1522,22,122,62,5663456345dba43623443efdaef3245345fea32534562663462323c000,22*d04567cde";	
    char wasteitems[BUFSIZ] = "#RAWWAASFRAMEA SATTIME COM ; , * .";
    //output array of filtering stage
    char *filteredstream;
    char *firstfilter;
    char *secondfilter;
    char *thirdfilter;
    char *fourthfilter;
    char *decodweek;
    char *decodtime;
    char *seventhfilter;
    char *eigthfilter;
    char *ninthfilter;
    char *tenthfilter;
    char *eleventhfilter;
    char *decodPRN;
    char *decodmsgtype;
    char *decodmsg;
    char *fifteenthfilter;
    char *decodPRC;
    int intPRN;
    char decoddate[9] = "20 06 05";  // ONLY FOR TEST!!!
    int main()
    printf( "remaining data:\n" );
    firstfilter = strtok( streaminput, wasteitems );
    //****************Opens a file in the temp folder to write temp array to************//
    secondfilter = strtok( NULL, wasteitems );
    thirdfilter = strtok( NULL, wasteitems );
    fourthfilter = strtok( NULL, wasteitems );
    decodweek = strtok( NULL, wasteitems );
    printf( "\n decodweek: %s", decodweek );
    decodtime = strtok( NULL, wasteitems );
    printf( "\n decodtime: %s", decodtime );
    seventhfilter = strtok( NULL, wasteitems );
    eigthfilter = strtok( NULL, wasteitems );
    ninthfilter = strtok( NULL, wasteitems );
    tenthfilter = strtok( NULL, wasteitems );
    eleventhfilter = strtok( NULL, wasteitems );
    decodPRN = strtok( NULL, wasteitems );
    printf( "\n decodPRN: %s", decodPRN );
    decodmsgtype = strtok( NULL, wasteitems );
    printf( "\n decodmsgtype: %s", decodmsgtype );
    decodmsg = strtok( NULL, wasteitems );
    printf( "\n decodmsg: %s", decodmsg );
    fifteenthfilter = strtok( NULL, wasteitems );
    decodPRC = strtok( NULL, wasteitems );
    printf( "\n decodPRC: %s \n\n", decodPRC );
    //intPRN = atoi(decodPRN);
    intPRN = strtol(decodPRN,NULL, 100);
    printf("intPRN: %3d, intPRN");

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Why are you using base 100? Also, strtol and atoi aren't your problems. Here, I'll prove it to you:
    #include <stdio.h>
    #include <stdlib.h>
    int main( void )
        char foo[] = "1234";
        int bar;
        bar = atoi( foo );
        printf("bar is %d\n", bar );
        return 0;
    Finally, please learn how to use printf, and turn on your compiler's warnings and listen to them!
    printf("intPRN: %3d, intPRN");

    printf("intPRN: %3d", intPRN);
    This isn't the first time I've showed you that you weren't using printf right.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2005
    ok, that was an error on the last line.

    if you lok at the previous part of the code, i think its pretty obvious i know how to use it.........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Converting a string to an integer
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2001, 10:01 PM