Atoi is to convert a string to int type data
Atof is converted to float type
Strtok are delimited strings.
The first example uses SSCANF, which is not used Strtok
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define max _line 2048int main () { file *fr; fr = fopen ("Test_group_box.txt", "R"); if (NULL&NBSP;==&NBSP;FR) { printf ("error!\n"); return - 1; } float t; char test_n_arr[ max_line]; // char *test_n_arr = (char*) malloc (sizeof (char) *max_line); char str1[50], str2[50], str3[50]; // char str1, str2, str3; // "Read each line of fr and assign each fields to three pointers " while (!feof (Fr)) { fgets (test_n_arr, max_line, FR); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SSCANF (test_n_arr, "%s\t%s\t%s", &NBSP;STR1,&NBSP;STR2 , &NBSP;STR3); t = atof (STR3); printf ("%s\t", str1); printf ("%s\t ", &NBSP;STR2); if (strcmp (str1," Group ") == 0) { printf ("%s\n", &NBSP;STR3); }else { printf ("%.2f\n", t); } } fclose (Fr); // free (Test_n_arr); return 0;}
Another example uses Strtok.
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define max _line 2048int main () { file *fr; fr = fopen ("Test_group_box.txt", "R"); if (NULL&NBSP;==&NBSP;FR) { printf ("error!\n"); return - 1; } float t; char *test_n_arr = (char*) malloc (sizeof (char) *max_line); char *str; // "Read each line of fr and assign each fields to three pointers " while (!feof (Fr)) { fgets (TEST_N_ARR,&NBSP;MAX_LINE,&NBSP;FR); str = Strtok (test_n_arr, "\ T"); int i = 0; while (str != null) { if ( i == 2) { if (strcmp (str, "qual\n") == 0) { printf ("%s", str); } else { t = atof (str); printf ("%.2f\n", t); } }else { printf ("%s\t", str); } i++; str = strtok (NULL, "\ T"); } } fclose (Fr); free (Test_n_arr); return 0;}
C language Atof,atoi, strtok and other functions usage