T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer is true or false in order to receive credit.
#include <stdio.h>
#include <string.h>
int run_through(int num, char **a)
{
int i;
int check=0;
for(i=0;i<num;i++)
{
printf("%s\n", *(a+i));
if(strcmp(*(a+i), "filename")==0)
{
check=1;
}
}
return check;
}
char** find_filename(int n, char **b)
{
int i;
int check=0;
for(i=0;i<n;i++)
{
if(strcmp(*b, "filename")==0)
{
b++;
break;
}
b++;
}
return b;
}
int main(int argc, char **argv)
{
int choice;
char **hold;
if(!(argc<6))
{
printf("Not happening.\n");
}
else
{
choice=run_through(argc, argv);
if(choice==0)
{
printf("Here.\n");
}
else
{
hold=find_filename(argc, argv);
printf("The filename is %s!\n", *hold);
}
}
}
1. false
(int argc, char **argv)
basically, argc is refering the muliple argument passed in, which includes the actual name of the program, as invoked by the user. argv contains the actual arguments, starting with index 1. Index 0 is the program name.
2. true
strcmp(*b, "filename") in that of C programming the function is used for the compare of two string.
if the both are same input given by then it will be true else false.
3 true
in every input or given the other argument the result will be change
if(strcmp(*(a+i), "filename")==0) that will be providing the status 1 or 0.
4. false
every function of argument are not same type
In C, a char**b means pointer to a pointer to b.
argc is refering the muliple argument passed in, which includes the actual name of the program, as invoked by the user. argv contains the actual arguments, starting with index 1. Index 0 is the program name
5. true
for e,g;
int main(int argc, char *argv[]) { printf("%d\n",argc); printf("%s\n",argv[0]); printf("%s\n",argv[1]); printf("%s\n",argv[2]); return 0; }
6. false
no depends upon the number of argument . because n will the integer which will pass the user. and char **b be the pointer of pointer of b. which hold the prevoius value of char.
7.true
it will hold the address of hold
for e,g
char *p1="ABCD"; p1="EFG"; printf ("%s",p1);
8.false
because argv[] is a pointer array which points to each argument passed to the program.argv[0] holds the name of the program itself and argv[1] is a pointer to the first command line argument supplied, and *argv[n] is the last argument. If no arguments are supplied, argc will be one, and if you pass one argument then argc is set at 2.
9.false
No , it will be change for pointer of holds the prevoius address.
10.true
./a.out name file executes on the equal choice 0 is.
excutes of file name like ./a.out name file here.
T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer...
Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wunzip: file1 [file2 ...]\n"); return 1; } else{ for(int i =1; i< argc;i++){ int num=-1; int numout=-1; int c; int c1; FILE* file = fopen(argv[i],"rb"); if(file == NULL){ printf("Cannot Open File\n"); return 1; } else{ while(numout != 0){ numout = fread(&num, sizeof(int), 1, file); c...
C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you. Use the given function to create the program shown in the sample run. Your program should find the name of the file that is always given after the word filename (see the command line in the sample run), open the file and print to screen the contents. The type of info held in the file is noted by the word after the filename:...
Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with a new string. * Append an s to the end of your input string if it's not a keyword. * Insert a period at the end, if you have an empty input string do not insert a period Problems: //Why does my code stop at only 2 input strings //If I insert a character my empty string case works but it's still bugged where...
In Programming language C - How would I convert my words char array into a string array so I can use the strcmp() function and alphabetically sort the words? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]){ int i =0; int j =0; int count =0; int length = strlen(argv[1]); for(i =0; i < length; i++){ if(isalpha(argv[1][i]) == 0 ||isdigit(argv[1][i] != 0)){ count ++; } printf("%c",argv[1][i]); } char *strings; int wordNum =0; int charNum =0; strings...
Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...
need this in c programming and you can edit the code below. also give me screenshot of the output #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define LINE_SIZE 1024 void my_error(char *s) { fprintf(stderr, "Error: %s\n", s); perror("errno"); exit(-1); } // This funciton prints lines (in a file) that contain string s. // assume all lines has at most (LINE_SIZE - 2) ASCII characters. // // Functions that may be called in this function: // fopen(), fclose(), fgets(), fputs(),...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing) pid_t pid; int j; //printf("Welcome to Project Three\n”); // For loop*/ for (j = 1; j...
-I need to write a program in C to store a list of names (the last name first) and age in parallel arrays , and then later to sort them into alphabetical order, keeping the age with the correct names. - Could you please fix this program for me! #include <stdio.h> #include <stdlib.h> #include <string.h> void data_sort(char name[100],int age[100],int size){ int i = 0; while (i < size){ int j = i+1; while (j < size){...
C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...