Smart Lab Helping Forum

Members Login
Username 
 
Password 
    Remember Me  
Post Info TOPIC: filehandling


Newbie

Status: Offline
Posts: 1
Date:
filehandling
Permalink  
 


sir me file se ek spceific line ko read kr different variables me store krna chta hn

liken compiler is ko ek string me read kr rha hai

e.g

line:

abc24

 

requried output:

char x= abc

int y=2

float z=0



__________________


Veteran Member

Status: Offline
Posts: 39
Date:
Permalink  
 

Abdul, aik tareeka yeh hai ke aik string me read kar lo, phir string se integer me copy karo. For example


char *x="abc124";

Now you can separate 4 by using int y = atoi(&x[3]); This will convert your characters 124 into an integer. Now if you print y it will be 124;

The atoi function converts a char to integer.


Hope this will help.

__________________


Veteran Member

Status: Offline
Posts: 39
Date:
Permalink  
 

Similarly you can use atof() function for floats. Try google for an example of atof or look in the book.



__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.



Create your own FREE Forum
Report Abuse
Powered by ActiveBoard