fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define MAX_PATH 300
  6.  
  7. char first [ 15 ][ 128 ] = { 0 };
  8. char second[ 15 ][ 128 ] = { 0 };
  9. char WorkingDir[ MAX_PATH ], txtPath[ MAX_PATH ];
  10.  
  11. int main()
  12. {
  13. strcpy( txtPath, "/tmp/list.txt");
  14.  
  15. FILE* op = fopen( txtPath, "w" );
  16. fputs("12345:67890\n",op);
  17. fputs("abcdef:ghijkl\n",op);
  18. fputs("mno:pqr\n",op);
  19. fclose(op);
  20.  
  21. FILE* fp = fopen( txtPath, "r" );
  22. if( fp ) {
  23. for( int i = 0; i < 15; i++ ) // 15 строк
  24. {
  25. char buf[ 128 ];
  26. if (fgets( buf, 128, fp ) == NULL) break;
  27. char * c = strchr( buf, ':' );
  28. if( c ) {
  29. *c = 0;
  30. strcpy( first[ i ], buf );
  31. strcpy( second[ i ], c + 1 );
  32. }
  33. }
  34. fclose( fp );
  35. }
  36. for(int i = 0; i < 15; ++i)
  37. {
  38. if (first[i][0] == 0) break;
  39. printf("%s -- %s\n", first[i], second[i]);
  40. }
  41.  
  42. }
  43.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
12345 -- 67890

abcdef -- ghijkl

mno -- pqr