reverse of the text in a textfile...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandra19
    New Member
    • Feb 2008
    • 3

    reverse of the text in a textfile...

    how could i reverse the word in a DAT file without using link and append the reverse text in the DAT file.? any suggestions? i already tried reversing it using linked list but i want to try another program with out using link list
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by sandra19
    how could i reverse the word in a DAT file without using link and append the reverse text in the DAT file.? any suggestions? i already tried reversing it using linked list but i want to try another program with out using link list
    Did you try using pointers? You could just point a pointer to the start, and then at the end, and print the second and decrement until it reaches the first...

    Comment

    • sandra19
      New Member
      • Feb 2008
      • 3

      #3
      Originally posted by sicarie
      Did you try using pointers? You could just point a pointer to the start, and then at the end, and print the second and decrement until it reaches the first...
      here is the start of code... could you please (if its ok with you) to add a little of your ideas here...? i really dont know how to start it..



      file_ptr = fopen("FIRST.DA T","r");
      if (file_ptr != NULL)
      {
      while ((buffer = fgetc (file_ptr)) != EOF)
      printf("%c", buffer);
      printf("\n");
      fclose(file_ptr );
      gotoxy(2,22);
      printf("String has been successfully displayed on screen.");
      getch();

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by sandra19
        here is the start of code... could you please (if its ok with you) to add a little of your ideas here...? i really dont know how to start it..



        file_ptr = fopen("FIRST.DA T","r");
        if (file_ptr != NULL)
        {
        while ((buffer = fgetc (file_ptr)) != EOF)
        printf("%c", buffer);
        printf("\n");
        fclose(file_ptr );
        gotoxy(2,22);
        printf("String has been successfully displayed on screen.");
        getch();
        My ideas are going to be basic - you're trying to code when you dont' know what you're trying to code. You're also trying to code with horrible, broken, old, non-standard libraries. Never ever ever ever ever ever use conio.h.

        So I would recommend creating your algorithm before you start coding. You can obviously get a line and print it out, but you don't even try to create a pointer, figure out the size of your string, point the pointer to the end of the string, and start decrementing and printing. So I would start there.

        Comment

        • sandra19
          New Member
          • Feb 2008
          • 3

          #5
          i already have the code in revesing the text in a textfile... basically, i used pointers(just like what u said( but i cant put it here since i wrote the code on our school)... another problem is,, how could i put the data in the pointer back to the dat file again? after reversing it..ideas??? please??

          Comment

          Working...