Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to read strings with commas by omitting them %[^,] not working for me
    text
    copied!<pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #ifdef _MSC_VER #include &lt;crtdbg.h&gt; // needed to check for memory leaks (Windows only!) #endif #define FLUSH while(getchar() != '\n') // Prototype Declarations int readFile(FILE* ifp,char** words); int main (void) { // Local Definitions FILE *ifp; FILE *ofp; char fnamer[100]=""; char **words; int *freq; int i; int numWords =0; // Statements words = (char**)calloc (1001, sizeof(int)); if( words == NULL ) { printf("Error with Calloc\n"); exit(111); } if (!(ifp=fopen("/Users/r3spectak/Desktop/song_row.txt", "r"))) { printf("sucks"); exit(100); } numWords = readFile(ifp,words); printf("%d", numWords); for(i=0;i&lt;numWords;i++) printf("\n%s",words[i]); #ifdef _MSC_VER printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Memory Leak\n"); #endif printf("\n\t\tEnd of Program\n"); printf("\n\t\tHave a great day!\n"); return 0; } /*===============readFile================= Pre: Post: This function */ int readFile(FILE* ifp,char** words) { // Local Variables char buffer[1000] = " "; int numWords = 0; // Statements while (fscanf(ifp," %s",buffer)!=EOF) { words[numWords] = (char*)calloc(strlen(buffer)+1,sizeof(char)); if( words[numWords] == NULL) { printf("\n"); exit(111); } strcpy(words[numWords],buffer); numWords++ ; } return numWords; } </code></pre> <p>The input file contains the following : Row, row, row your boat, Gently down the stream. Merrily, merrily, merrily, merrily, Life is but a dream. </p> <p>After fscanf my array prints</p> <pre><code> Row, row, row your boat, and so on </code></pre> <p>what i want is,</p> <pre><code>Row row row your boat </code></pre> <p>i've tried %[^,.\n] and its not working for me. it prints rubbish</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload