Scanf function

xiaoxiao2021-03-05  22

I saw the problem in 9CBS today as follows:

There is a text file, the form is as follows: AAA, BBBCCC, DDDEEE, FFF now, want to write a function, read these six fields into a two 3-dimensional string TEMP1 is {AAA, CCC, EEE} Tmep2 is { BBB, DDD, FFF}, how do this function in C language? Do you use Fscanf? FSCANF does not seem to be recognized, a separator.

Among them, Coldcrane has given the following reply:

Char S [6] [16] = {0,}; fscanf (fp, "% [^,],% [^ / n] / n% [^,],% [^ / n] / n% [^ ,],% [^ / n] ", s [0], s [1], s [2], s [3], s [4], s [5]);

I feel very wonderful, I tried it, it's really good!

#include #include using namespace std;

INT main () {file * fp = fopen ("c: //aaa.txt", "r"); if (fp == null) {Printf ("Open file error / n"); exit (1); CHAR S [6] [16] = {0,}; // fscanf (fp, "% [^,] s,% [^ / n] S / N% [^,] s,% [^ / N ] S / N% [^,] s,% [^ / n] s ", s [0], s [1], s [2], s [3], s [4], s [5]) FSCANF (FP, "% [^,],% [^ / n] / n% [^,],% [^ / n] / n% [^,],% [^ / n], S [ 0], s [1], s [2], s [3], s [4], s [5]); for (int i = 0; i <6; i) Printf ("% s / n ", s [i]); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-38245.html

New Post(0)