int, long in char *
Sorry i,ve got probably stupid question, but i learn C and C++ by myself and i've got some wholes in it. So, how can i change my int, long or else value in common char value. I know that static_char doesn't work. How can i write int value in file?? Could you help me??
|
If you want to change int into char
Use type casting i.e , suppose main() { int i=97; char ch; ch=(char )i;// This is type-casting... printf("%c",ch); } Then the output will be 'a' ; To write an int or string onto a file u can write as it is .... fprintf("%s %d ",some_string,some_int); while reading fscanf("%s %d",read_string,read_int) ; will work fine ..... P.S :- Check out man pages for fprintf and fscanf then u'll know |
Re: int, long in char *
Quote:
Code:
fprintf(fp,"%d",&n); Code:
int n; if you got any other probs, u are welcome. |
Quote:
|
Hmm, I wrote up your program Vanqiusher and that's i received in the file: -1073743164, so it doesn't want to work
Another question, what about writing to shared memory, in example i mapped file or i want to send data from one process to second through shared memory This data is of course some int, long or double not a string How can I do that??? |
Quote:
U mean my program is not working? I didn't get ya.. Quote:
|
Re: Re: int, long in char *
Quote:
No wonder the code didn't work ..... It should be fprintf(fp,"%d\n",n); "&n" means the address of n |
stupid typo...:(
yeah..it should b fprintf(fp,"%d\n",n); sorry for that |
Now it of course works great :) Great Thanks
Do you know somebody is really keen on programming in linux at C, some guru who i can send my question via mail?? (i am expecially interested at work with file descriptors (you know write, open, close functions) instead file pointers, altough on other hand your program will we be very usefull for me, because i can exchange file pointer by file descriptor and work on file with written int number). But it might take me to much time... |
Quote:
|
No trouble, I can probably speek better than you polish :D so i can be useful, send me your questions on this mail:
spartanie@interia.pl |
All times are GMT -5. The time now is 07:10 AM. |