c - need to read an array of chars from a data file, I have a loop setup and it just outputs numbers not the chars I would expect -


#include <stdio.h> #include <math.h> #define inputfile "c:\\users\\failedpilgrim\\documents\\undprog\\wind.txt"  /* main function */ int main(void) {     /* declare variables */     char city_datatype[21];     double wind_speeds [12][5], total_rows[12] ={0}, total_cols[5]={0},      average_rows[12], average_cols[5];     int i, j, nrows, ncols;     file *input = null;      /*open input file*/     input= fopen(inputfile, "r");         /*verify input file*/     if (input==null)     {         printf ("\n\n\nerror opening input file.\n\n");         printf ("\n\nprogram terminated...\n\n\n\n");         return 1;     }      /*read title*/     (i=0; i<=21;i++)     {         fscanf(input, "%c", &city_datatype[i]);         printf("%d",city_datatype[i]);         ... 

this reading data file starts phrase "centerville-windspeed" task read array , print array. why code not work? output bunch of seemingly random numbers

your printf, @ end of last loop, printing chars integers via "%d" format string.

if want print each city_datatype characters, try use "%c" instead.


Comments

Popular posts from this blog

Add new key value to json node in java -

javascript - Highcharts Synchronized charts with missing data points -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -