"Parse" line of code doesn't allow code to execute [closed] - c

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Cheers, I've isolated the error but I'm not sure how to fix it. Apparently, this line of code,(C language):
parse(getenv("QUERY_STRING"));
It does successfully compile, however when I run the executable the following pops up: puu.sh/nQi41/40e81c4494.png
When I simply comment out that specific line, the code compiles and runes perfectly.
Any possible solutions to this? Thanks in advance

Replace:
parse(getenv("QUERY_STRING"));
by:
char *querystring = getenv("QUERY_STRING");
if (querystring == NULL)
{
printf("Could not get querystring");
exit(1);
}
parse(querystring);
... and read the documentation of getenv.

Related

C language Redirection [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I have been asked to make a program named easter.c Now this program involves file handling. Now whenever I try to run the redirection, the terminals shows a message
zsh: command not found: easter
Following is the screenshot. Kindly view the screenshot and help.
./easter
or
export PATH=.:$PATH
Ideally, we should add the complete path of the current directory instead of .

How can I print file path in C inside Minix OS? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have to edit the exec syscall inside the Minix OS, in a way that every process created by it should print the program file path + program name:
for example, if I type ls inside the terminal, the next line should show me path/to/ls/ls
always in this format: filepath/programName.
I already managed to print the program name, but I am having problems with the file path. Can somebody show me how can I print it?
here is the code for sys_exec.c:
#include "syslib.h"
#include "stdio.h" //I included this library
int sys_exec(endpoint_t proc_ep, vir_bytes stack_ptr, vir_bytes progname,
vir_bytes pc, vir_bytes ps_str)
{
/* A process has exec'd. Tell the kernel. */
message m;
m.m_lsys_krn_sys_exec.endpt = proc_ep;
m.m_lsys_krn_sys_exec.stack = stack_ptr;
m.m_lsys_krn_sys_exec.name = progname;
m.m_lsys_krn_sys_exec.ip = pc;
m.m_lsys_krn_sys_exec.ps_str = ps_str;
//edited by me
puts((char*)progname);//this prints the program name
return _kernel_call(SYS_EXEC, &m);
}
and some image as reference:
this is what happens when I type ls
I was on the wrong path, the file I needed to edit was \usr\src\minix\minix\servers\vfs\exec.c, I was trying to edit \usr\src\minix\minix\lib\libsys\sys_exec.c.
Inside the right file I had access to a variable called fullpath inside the get_read_vp function. I imported stdio.h and then typed printf("executing: %s\n", fullpath); inside the function.

How to fix an error of reading a text file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have tried to reading a text file but the array stores only the last line of the text file.
char cleanedText[10000]={'\0'};
while(!feof(fileptr))
{
fgets(cleanedText, 10000 , fileptr);
}
But,the cleanedText stores only the last sentence which is written in the text line.
For example these two is written in the text,
asdasdasd
thisisus
When i print the cleanedText.
The screen just shows thisisus.
What is the problem?
Each call to fgets writes into the same place, overwriting what was there previously.

file opening and writing in c [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
FILE *fp1;
if((fp1 = fopen("abc.txt", "w")) != NULL)
{
fprintf(something);
fclose(fp1);
}
I am trying to compile this file and all related file using developer command prompt and trying to run it from there. But while running it says this filename.exe has stopped working. It is not able to create the file abc.txt .
You almost certainly don't have write permission in the directory you are attempting to create abc.txt in. The code would be better if you handled the error case:
if ((fp1 = fopen("abc.txt", "w")) == NULL) {
perror("abc.txt");
exit(1);
}
My guess is your output will be "abc.txt: Permission denied"
You also have a problem that your fprintf() ought to be fprintf(fp1, something) (where something is presumably your format string and some variables).

How to convert .byt to .txt in matlab [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I need to convert .byt file to .txt, I believe it can only be done in matlab. I used this code, but this doesn't seem to work:
img = fopen('myfile.byt','r');
save('myfile.txt','img');
fid = fopen('myfile.byt','r');
data = fread(fid,inf,'single');
fclose(fid);
% Manipulate your data, then...
fid = fopen('myfile_new.byt','w');
fwrite(fid,data(:),'single');
fclose(fid);
I should see how your data looks like if you want me to figure out how to save it in txt format.

Resources