Link to home
Start Free TrialLog in
Avatar of HumanData
HumanData

asked on

text edit and files

How do I read and write strings to and from a number of text edits such as in an address book where you have a first name, last name, and so on to read and write to a file?
Avatar of HumanData
HumanData

ASKER

Edited text of question
What is text edit? Can you pls give me more details.
The following program does what I think you want:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main(void)
{
      FILE *aFile;
      char name[256],lastname[256],firstname[256];

      /* open file for write */
      aFile = fopen("Test file","w");
      if (NULL==aFile) {
            printf(" cannot open file for write\n");
            return 0;
      }
      
      /* write some strings */
      strcpy(name,"LastName1, FirstName1");
      fprintf(aFile,"%s\n",name);
      
      strcpy(name,"LastName2, FirstName2");
      fprintf(aFile,"%s\n",name);
      
      fclose(aFile);
      
      /* open file for write */
      aFile = fopen("Test file","r");
      if (NULL==aFile) {
            printf(" cannot open file for read\n");
            return 0;
      }
      
      fscanf(aFile,"%255s %255s",lastname,firstname);
      printf("Read string: %s %s\n",lastname,firstname);
      
      fscanf(aFile,"%255s %255s",lastname,firstname);
      printf("Read string: %s %s\n",lastname,firstname);
      
      fclose(aFile);

      return 0;
}

If by "text edit" you mean a TEHandle, then you would get the text from (**te).hText instead of using strcpy.  The text at offset N into a TERec is at (*(**te).hText + N), where te is the TEHandle.
Please provide answers in C.

By text edit I am meaning a field of text (TEtextBox).
ASKER CERTIFIED SOLUTION
Avatar of boonstra
boonstra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial