Hello,
I wrote this simple program which prints all the arguments given to a program.
My code is straightforward and this is it
Code:
#include <stdio.h>
#include <malloc.h>
int i = 0;
int main(int argc, char** argv)
{
printf("\nargc == [%d]",argc);
printf("\nthe arguments are ");
for(i=0;i<argc;i++)
{
printf(&q
A program from apue.
#include "apue.h"
#include <fcntl.h>
int main(int argc, char *argv[])
{
if(argc!=2)
err_quit("usage: a.out <pathname>");
if(access(argv[1], R_OK)<0)
err_ret("access error for %s",argv[1]);
else
printf("read access OK\n");
if (open(argv[1], O_RDONLY)) {
err_ret("open error for %s", argv[1]);
} else {
Original source code :#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int max = -1;
int mb = 0;
char* buffer;
if(argc > 1)
max = atoi(argv[1]);
while((buffer=malloc(1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 1024*1024);
mb++;
printf("Allocated %d MB\n&quo
I am trying some similar code, I did pacman -S opencv, and then I am trying to compile a hello world in cpp named helloOcv.cxx (I had left it as cxx from when I was going to use cmake).
Code of baul :)
Code:
/*
* Hanx [Proyecto Fedora Peru] wth Code
* crc.c - app
*
* This program is private version, for anti-educational purposes and without any
* explicit or implicit warranty; in no event shall the author or
* contributors be liable for any direct, indirect or incidetal damages
/*
* program accept argument from stdin as well as command line
* run it with
* echo "1 2 3" | ./a.out
* OR
* ./a.out 1 2 3
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
int fromstdin = 0;
int i = 1;
char infile[200];
if (argc == 1) fromstdin = 1;
if (fromstdin)
{
memset(infile, 0, 200);
while (scanf("%s", infile) != EOF
Guys, I have the following code
Code:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
void read2();
main(int argc, char** argv)
{
int pid,status;
pid=fork();
if ( pid == 0 )
{
read2(argv[1], argv[2]);
see i have below code
#include<stdio.h>
int main ( int argc, char *argv[] )
{
int i=0;
for(i=1;i<argc-1;i++)
printf(" %s \n",argv[i]);
return 0;
}
compiles and run as follows
gcc test.c
./a.out 1 * 2
and now its o/p is scarred..!
o/p is :
1
a.out
Desktop
Documents
Downloads
ipmsg.log
linux-fusion-3.2.6
Music
Pictures
Public
Te
I'm trying to make a program which is getting 2 pathes for files to main, and calling linux' cmp command in order to compare them.
If they equal, I want to return 2, and if they're different, 1.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, const char* argv[])
{
pid_t pid;
int stat;
//child process
if ((pid=fork()