|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
user command 'file'
Can anyone help me ...I have to mimic the output of when a user types say file text.c in a unix terminal to return --
text.c : ANSCII c program text --------------------------------- const char * longfiletype(const char *name){ char tempfile[SIZE]; tmpnam (tmpfile); char lfile[SIZE]; strcpy(lfile,'file'); strcat(lfile,name); strcat(lfile,'>'); strcat(lfile,tmpfile); system('lfile'); FILE * file = fopen(tmpfile, "r"); |
|
#2
|
||||
|
||||
|
Take out the quotes in the call to system. You need to call it like this:
system(lfile); Also, for C, all the variables need to be declared on top of the block, so you can't declare FILE *file midway in the code. With C++, this is ok, but not in C. Code:
char tempfile[SIZE]; char lfile[SOMESIZE]; char buf[SIZE]; FILE * file; tmpnam (tmpfile); strcpy(lfile,'file'); strcat(lfile,name); strcat(lfile,'>'); strcat(lfile,tmpfile); system(lfile); file = fopen(tmpfile, "r"); fgets(buf, SIZE, file); fclose(file); /* Do something with buf here */
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
stoo23:
I was trying to reply to your PM, but your inbox is full - system won't let you receive more PM until you clear some out. |
|
#4
|
|||
|
|||
|
please stop this s..*ies
never heard about sprintf() and popen() man pages are sure available |
|
#5
|
||||
|
||||
|
Heh, I would have recommended popen(), but the original poster insisted on not posting his code publicly and PMing me instead, even AFTER I requested that they post on the C forum. Then, it appears he PMd a lot of people the same question and filled up his inbox
. Finally, the OP posted part of the question on this forum so I figured it deserved some sort of reply, though not necessarily the best one. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > user command 'file' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|