I wish to output a string from a textbox to another file, here is what I wrote:


In my hello.txt:
Set wallpaper=

My problem is how can I control where to fprintf my string. In this example, how can I output the textbox text to file hello.txt so that the file become :Set wallpaper= "...." ,the ... is text from the textbox.
So can anyfren tell me how to control string output to that location?

I am not sure I understand what you want. Maybe, the following code can help you. I write it using C++, you can translate it to C. This code can replace the text Set wallpaper="aaaa" with Set wallpaper="text"

int main(int argc, char *argv[])
  string text = "text";
  string str;
  vector<string> fileContent;
  ifstream infile("hello.txt");
  while ( getline(infile, str) )
    if ( str.find("Set wallpaper=") != string::npos )
      str = "Set wallpaper=\"";
      str += text;
      str += "\"";
  ofstream outfile("hello.txt");
  for (int i=0; i<fileContent.size(); ++i)
  return EXIT_SUCCESS;

Here's how to do it. fprintf(myfile,"Set wallpaper= \"%s\"\n",textbox1->text);

Here's how to do it. fprintf(myfile,"Set wallpaper= \"%s\"\n",textbox1->text);

I do not think this is what he want. I think his condition is like that:
there are a lot of line in file hello.txt , like
Set wallpaper=
Set color=
Set ....=.....
what he want is find out the line contain "Set wallpaper" and replace it with Set wallpaper="the text from the textbox"

>>So can anyfren tell me how to control string output to that location?
If you want to change the text in the file itself, then you will have to rewrite the entire file. When you come across the line "Set wallpaper" then write out the new text into the new file.
Here is some pseudocode for you to use.

open original file
open new output temp file

for each row in input file
   call fgets() to read the line
   check for "Set wallpaper"
   if check is true then write new text to output file
   otherwise if check is false then just write the entire row to output file
end of while loop