It's been awhile, since i did nothing..
So anyway i am constantly working on something that requires messing with text in files you know >.> those things are aways messy.
So what i am trying to accomplish is the following:
If the chars in a line are more then (for e.g 10) then the code finds the last char and converts it to a new line. What i have been doing is only this bit of code, with actually works:
- Code: Select all
void NewLine(const char * fname, char * textArray, int maxChars)
{
FILE * pFile = fopen(fname, "r");
char * line = textArray;
textArray = line;
if (strlen(textArray) > maxChars) { line[maxChars-1] = '\n';}
fclose(pFile);
}
And the result is:
according to:
- Code: Select all
NewLine("test.txt", textArray[0], 6);
So it finds the 6th character with is "r" (from "8 chars(\n)") and it converts it to \n for the reading. But what i want is not that to happen. Maybe seeking for the last space should work.
Maybe i can seek for space with something like:
- Code: Select all
int seekChar (const char * str, char chr)
{
char * pointer;
pointer=strchr(str, chr);
while (pointer != NULL)
{
sprintf (text, "Order: %d", pointer-str+1);
pointer=strchr(pointer+1, chr);
}
return pointer-str+1;
}
But it must must find the first space before the last allowed char mentioned. Maybe something like:
- Code: Select all
void maxchr(const char * FILENAME, char * TEXTARRAY, int MAXCHARS)
{
FILE * pFile = fopen(fname, "r");
char * LINE = TEXTARRAY; TEXTARRAY = LINE;
char * POINTER; POINTER = strchr(LINE, ' ');
while )(POINTER != NULL)
{
if (strlen(TEXTARRAY) > MAXCHARS && MAXCHARS = pointr-str+1)
{
line[maxChars] = '\n';
}
}
POINTER = strchr(POINTER+1, ' ');
}