************************************************** ********
Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
using namespace std;
struct address{
int h,st;
char city[30],country[25];
};
struct info{
char name[20];
char fname[20];
char desig[20];
struct address add;
};
int main(){
struct info zia;
FILE*fp;
fp=fopen("new.txt","w");
if(fp!=NULL){
cout<<"Name : ";
gets(zia.name);
cout<<"Father Name : ";
gets(zia.fname);
cout<<"Designation : ";
gets(zia.desig);
cout<<"House # : ";
cin>>zia.add.h;
cout<<"Street # : ";
cin>>zia.add.st;
fflush(stdin);
cout<<"City : ";
gets(zia.add.city);
cout<<"Country : ";
gets(zia.add.country);
fprintf(fp,"%s %s %s %d %d %s %s",zia.name,zia.fname,zia.desig,zia.add.h,zia.add.st,zia.add.city,zia.add.country);
}
else{
cout<<"File can't be Created";
}
getche();
return 0;
}
************************************************
File Create with the Output. Ok the word with in the parenthesis are just to make clear that it was where in the structure while writing to file.
************************************************
Tanzeelur Rehman (name) Ubaidullah (fname) Software Developer (desig)1 (add,h) 3 (add, st) Islamabad (add,city) Pakistan (add,country)
************************************************
now i want to write these from file to structure, The issue is that with in the name i have spaces, in designation i have spaces too, I want to read the complete name in one string and complete designation in one string.