Problem in my script ..lookig for help

Talk about making games.

Problem in my script ..lookig for help

Postby bat78 » Thu Nov 21, 2013 12:48 am

Hi developers!
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:
result.png


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, ' ');
}
Last edited by bat78 on Fri Nov 22, 2013 3:15 pm, edited 3 times in total.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Problem in my script:

Postby skydereign » Thu Nov 21, 2013 1:35 am

bat78 wrote:But what i want is not that to happen. Maybe seeking for the last space should work.

What does that mean? It sounds like from the rest of the post, it does exactly what you want it to. What should the proper output look like?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Problem in my script:

Postby bat78 » Thu Nov 21, 2013 1:51 am

Okay we have this text document:
8 chars
9 chars
10 chars

The code should do for example:
If the first line have more then 7 characters, the next characters goes to the next line. So far i coded something (but i haven't tested it and i doubt it'll work):
Code: Select all
void maxchr(const char * FILENAME, char * TEXTARRAY, int MAXCHARS)
{
   FILE * pFile = fopen(FILENAME, "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, ' ');
}

nvm this above gives more errors then my life ^
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Problem in my script:

Postby bat78 » Thu Nov 21, 2013 2:40 am

Generally this script:
Code: Select all
void maxCharLenght(const char * fileName, char * content, int maxChr)
{
   FILE * file = fopen(fileName, "r");
   char * line = content;
   char * pointer = strchr(content, ' ');
   content = line;
   
   //while (pointer != NULL)   {
   if (strlen(content) > maxChr) {
   if (pointer - content + 1 == maxChr) {
   line[maxChr-1] = '\n';
   pointer = strchr(pointer + 1, ' ');
   //}
   }
   }
   fclose(file);
}


Does send the rest chars in the next line if the char is specified BUT:
-It does not recognize spaces or escapes for null (NULL, '\0', ' ')
-It does not send the rest chars in the next line in the next textArray[num]
Shortly i need code that do the following:
Opens a .txt, check if there are more then x chars at the specified line and if they are, it sends the rest of the chars (after x) to the next line with is the next textArray[] And it shouldn't loose information such as another lines or char/chars like in my case the code is doing, by converting char to new line char
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Problem in my script ..lookig for help

Postby next389 » Thu Nov 24, 2016 11:43 am

Understood nothing. clarify please!
next389
 
Posts: 10
Joined: Wed Nov 23, 2016 12:59 pm
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron