c

Using cd command with fork in c

爱⌒轻易说出口 提交于 2021-02-17 05:15:39
问题 Is it possible to change around directories using the fork command? Without going too much into my code I have the following: childpid = fork(); if (childpid >= 0) { if (childpid == 0) { ret = execvp(argv[0],argv); exit(ret); } else { waitpid(childpid,&status,0); ret = WEXITSTATUS(status); } } The above works fine when I'm entering basic command like ls , pwd , etc.. Is it possible to implement a way to use the cd function? I can type the command cd .. but it doesn't do anything. For example

exception in for loop? [duplicate]

烂漫一生 提交于 2021-02-17 05:15:38
问题 This question already has answers here : EXC_BAD_ACCESS when using strcpy()? (3 answers) Why Can I not modify a string literal in c? (1 answer) Closed 7 months ago . Why my code returns: Exception: EXC_BAD_ACCESS (code=2, address=0x10d637fa2) in the first time it enters the for loops? void unAnnoyWord(char *str) { char *out = str, mostAnnoying = 'a'; do { if (*str != mostAnnoying) { *out = *str; } } while (*str++); } char *str = "hakuna matata"; unAnnoyWord(str); 回答1: Perhaps this is what you

Contents of a f77 unformatted binary file

青春壹個敷衍的年華 提交于 2021-02-17 05:14:00
问题 I have an f77 unformatted binary file. I know that the file contains 2 floats and a long integer as well as data. The size of the file is 536870940 bytes which should include 512^3 float data values together with the 2 floats and the long integer. The 512^3 float data values make up 536870912 bytes leaving a further 28 bytes. My problem is that I need to work out where the 28 bytes begins and how to skip this amount of storage so that I can directly access the data. I prefer to use C to

Contents of a f77 unformatted binary file

▼魔方 西西 提交于 2021-02-17 05:12:04
问题 I have an f77 unformatted binary file. I know that the file contains 2 floats and a long integer as well as data. The size of the file is 536870940 bytes which should include 512^3 float data values together with the 2 floats and the long integer. The 512^3 float data values make up 536870912 bytes leaving a further 28 bytes. My problem is that I need to work out where the 28 bytes begins and how to skip this amount of storage so that I can directly access the data. I prefer to use C to

Array has incomplete element type. What does this mean? [duplicate]

旧街凉风 提交于 2021-02-17 05:01:48
问题 This question already has answers here : Why do we need to specify the column size when passing a 2D array as a parameter? (6 answers) Closed 5 months ago . I want to create an array that has that stores the multiplication values of any integer n. After that, I would like to pass that array into another function and print out the array. However, I get the following error: My code: This is my .c file: #include "multiplication.h" #include <stdio.h> int main(){ int num; int arr=multiplication(4)

Expected ';' identifier or '(' token before 'void'? [closed]

一世执手 提交于 2021-02-17 05:00:25
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question I am trying to compile my code and I am getting the Expected ';' identifier or '(' token before 'void' error on C:10:1.. can't seem to find the typo if someone can help me out I would appreciate it! I have provided my code down below I am sure it is just a

Expected ';' identifier or '(' token before 'void'? [closed]

为君一笑 提交于 2021-02-17 04:59:25
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question I am trying to compile my code and I am getting the Expected ';' identifier or '(' token before 'void' error on C:10:1.. can't seem to find the typo if someone can help me out I would appreciate it! I have provided my code down below I am sure it is just a

What happens when you call close() on a pipe file descriptor that was duplicated with dup2()?

两盒软妹~` 提交于 2021-02-17 04:52:34
问题 I have a question regarding file descriptors in Unix and C programming. Let's say I use pipe(fd) to get file descriptor 3 and 4 for the pipe ends, 3 connects to the read end and 4 to the write end. Now I use dup2(fd[write_end],1) to copy the descriptor of the write end (which was 4) to file descriptor 1 in my process. If I now do close(fd[write_end]) will it close descriptor 1 or descriptor 4? 回答1: After a successful call to dup2 , both file descriptors are valid. When you then call close(fd

For loop inside for loop works without a curly brackets?

我的梦境 提交于 2021-02-17 04:51:11
问题 How does a for loop inside for loop works without a curly braces? As you can see there's two for loops inside while loop first too but they require braces but in the main statement in that nested loop no braces are required? I am confused on that can anyone explain that? #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int n; scanf("%d", &n); int size=2*n-1; int start=0; int end=size-1; int a[size][size]; while(n != 0) { for(int i=start; i<=end;i++){

Split String in C to recognize consecutive tabs

Deadly 提交于 2021-02-17 04:32:04
问题 I have a file that has certain fields separated by tabs. There will always be 17 tabs but there order can vary, such as.. 75104\tDallas\t85\t34.46\t45.64 75205\tHouston\t\t37.34\t87.32 93434\t\t\t1.23\t3.32 When I use strtok in the following fashion while (fgets(buf, sizeof(buf), fp) != NULL) { tok = strtok(buf,"\t"); while(tok != NULL) { printf("%s->",tok); tok = strtok(NULL,"\t"); } } I get all the tokens, but double tabs \t\t or more are ignored. However, I need to know when a field is