how to read back a char as an int in c -


i scrolling through file of characters , saving data array. file looks this: http://pastebin.com/dx4hett0

i've deleted header information it's literally text file numbers in it. want convert these char numbers bytes in program can conversion maths on them.

my code follows:

#include <stdio.h> #include <stdlib.h>  #include "../dataprocessing/include/packet.h"  int main ( int argc, char *argv[] ) {     /*     // assume argv[1] filename open     file *file = fopen( argv[1], "r" );     */      file *file = fopen("c:\\log_hex.txt", "r");      /* fopen returns 0, null pointer, on failure */     if ( file == 0 )     {         printf( "could not open file\n" );     }     else      {         int x;         int count = 0;         int bytearray[99999];         /* read 1 character @ time file, stopping @ eof,            indicates end of file.  note idiom of "assign            variable, check value" used below works because            assignment statement evaluates value assigned. */         while  ( ( x = fgetc( file ) ) != eof )         {             bytearray[count] = x;             printf( "%c", x );             count++;         }         fclose( file );         getchar();     } } 

bytearray gets filled characters not in way want - i'm getting character 0 represented numerical value 53, 4 represented 52, space represented 32.... how can read character number, , make number char value in bytearray?

you reading in byte values in ascii. need either use library function strtol convert actual values.

although think there typo in question - doubt 0 coming out 53, that's ascii 3

if know digit, can do

x-='0'; 

to value.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -