-
cyberfish, I certainly understand and appreciate your concern.
Sometimes, I don't understand such simple as
system("command", "arg1", "arg2"); where arg1 or arg2 can be variables..
in perl
would be so difficult to execute in c programming but I certainly enjoy the challenge of programming and definitely look forward to learn more in programming in c.
As to trying things out piece by piece of code is perhaps due to my perl background but I certinaly think actually typing and see what compiler spits out either confirms what I know or what i dont know and i think it helps..
-
The system function just takes a single string as an argument. If you need the contents of members of argv, then you will need to first pass those to a buffer to prepare them for output. A variable, and a string which is the same as the name of a variable, are usually not the same thing with regards to their usefulness.
Code:
int x = 5;
...
printf( "x" );
That doesn't print 5. That's the point they were trying to make earlier.
Quzah.
-
sorry, Quzah, but I just tried your code and it actually printed 5.. ?
Code:
[root@Xclient c]# cat variable_print.c
#include <stdio.h>
main()
{
int x = 5;
printf("x");
}
result
Code:
[root@Xclient c]# gcc -o variable_print variable_print.c
[root@Xclient c]# ./variable_print
x[root@Xclient c]#
-
Uhh...
where do you see a 5 in that?
-
my bad,
of course only below code would product 5.. I am still trying to see what everyone was talking about earlier.. will get back to you. thanks
Code:
#include <stdio.h>
main()
{
int x = 5;
printf("x");
printf("%i",x);
}
-
so far this is working fine for me..
Code:
#include <stdio.h>
#include <string.h>
main( int argc, char *argv[] )
{
//char filename[29];
char file_n[100];
char file_n2[100];
sprintf(file_n, "zcat -d %s | ", argv[1]);
printf("never %s\n",file_n);
sprintf(file_n2, "grep %s ", argv[2]);
strcat(file_n, file_n2);
FILE* f = popen(file_n, "r");
if(f)
{
char buffer[256];
while(fgets(buffer, sizeof(buffer), f))
{
printf("%s", buffer);
}
fclose(f);
}
}