I don't know what's wrong but the succeeding strings are not properly read by fgets. else { initArray(word1); //first string fgets(word1, 29, fileIn); printf("word1: %s\n", word1); len = strlen(word1); if(word1[len-1] == '\n') word1[len-1] = '\0'; while(!feof(fileIn)) { //succeeding strings in next line initArray(word1); fgets(word1, 30, fileIn); printf("word1: %s\n", word1); len = strlen(word1); if(word1[len-1] == '\n') word1[strlen(word1)-1] = '\0'; fgetc(fileIn); } fclose(fileIn); } } texts: ABCD asnjf fkj read: ABCD snjf kj Can you give me an idea what's wrong?

Member Avatar
Member Avatar
+0 forum 4

I have a bit of a baffling problem! I'm writing a tag matcher in XML and whenever I run the below procedure, I get a garbage value after the name of every tag **except for the first one**. When I add the array text to the parameters list, the garbage value goes away (I had it there during initial debugging) even though it isn't actually referenced at any point in the procedure. Another thing, is that while reading a tag, it doesn't seem to want to recognize spaces. For example, <img src="img.png"/> reads as imgsrc="imgpng" instead of img, but only …

Member Avatar
Member Avatar
+0 forum 1

Ok. As the title says I tried many times to simply write a program that rewrites a file to remove null characters. I confirmed with a hex editor that the file in question has tons on null characters, on average about 1 of every 2 characters in null. So my last attempt: #include <stdlib.h> #include <stdio.h> int main() { FILE *f = fopen("main2.c","r"); FILE *t = fopen("temp","w"); int c; int count = 0; while((c = fgetc(f))!=EOF) { if(c) { fputc(c,t); } else { printf("null found\n"); } } fclose(f); fclose(t); FILE *n = fopen("main2.c","w"); FILE *w = fopen("temp","r"); while((c=fgetc(w))!=EOF) { fputc(c,n); …

Member Avatar
Member Avatar
+0 forum 10

The idea for this came from another thread in the C++ forum that wanted to duplicate the _getdelim() function that is supported by GNU compilers g++. I made one major change in that this version does not allocate new memory every time it is called, which is grossly inefficient. Instead, this function only allocates new memory if the pointer to pointer passed to _getdelim() is NULL. If not NULL then it assumes the calling program has allocated the memory. The function might expand the size of the line buffer if the number of characters read exceeds the length of the …

Member Avatar
Member Avatar
+2 forum 3

The End.