Ok, I have this code using fscanf, basically what I want to do is to send lets say a string "y = " followed by a number. Then I close the file and then reopen it and scan it to take out the string and the number. The problem is that when I scan it, it doesnt give me the input data that I sent. Then what I want to do is to only send my desired data to another file. Can someone help me please?
Code:
#include <stdio.h>
#include <iostream>


using namespace std;

int main ()
{
  int i;
  int x;
  
  char str [80];
  
  FILE * pFile;
  FILE * pFile2;
  FILE * pFile3;
//Writing to file
  pFile = fopen ("aplus.txt","w+");
  fprintf (pFile, "%s %d", "Y =",30);
  printf ("%s %d\n",str,&i);
  fclose (pFile);
  
  system ("pause");
  //Getting from file
  pFile2 = fopen ("aplus.txt","r");
  rewind (pFile2);
  fscanf (pFile2, "%s", str);
  fscanf (pFile2, "%d", i);
  
 //Writing needed information to file
  pFile3 = fopen ("aplus2.txt","w+");
  fprintf (pFile3, "%d");
  
   fclose (pFile2);
  fclose (pFile3);
  
  printf ("%d and %s \n",&i, str);
  
  system("aplus.txt");
  system("aplus2.txt");
  
  return 0;
  
}

Last edited by shabbir; 9Sep2008 at 09:27.. Reason: Code block