-2

I am trying to find out how to pass output value of a function into command line in a C file. The name of the variable is "Cext", "Cabs". The default behavior of the program is to create a folder which contains C files in which the output is printed. The code where I have to edit is as follows:

enter image description here

In the lines 922-925,

CCfile=FOpenErr(fname,"w",ONE_POS);
PrintBoth(CCfile,"Cext\t= "GFORM"\nQext\t= "GFORM"\n",Cext,Cext*inv_G);
PrintBoth(CCfile,"Cabs\t= "GFORM"\nQabs\t= "GFORM"\n",Cabs,Cabs*inv_G);
FCloseErr(CCfile,F_CS,ONE_POS);

What changes I should make? So i can get the value on the command line and than store it in an array. Any links/ text to read or sample code would be highly appreciated? I have previously looked at these links but i still haven' figured it out

  1. Pass arguments into C program from command line
  2. Arguments to main in C
  3. https://www.geeksforgeeks.org/command-line-arguments-in-c-cpp/
  4. https://techvidvan.com/tutorials/command-line-arguments-in-c/
  • 1
    Post code as text, not as pictures. Also why did someone spam random `restrict` all over this code? Is there a reason or did they just not know the purpose of that keyword? – Lundin May 11 '22 at 13:47
  • I was trying to post it as a code but i was getting errors – Hamzah Khan May 11 '22 at 13:48
  • i got this code from my supervisor – Hamzah Khan May 11 '22 at 13:49
  • I think you meant to ask about "Passing values **from** the command line **to** a function-C language". If so, please fix it, by editing your question. Otherwise, it's confusing. – rici May 11 '22 at 15:11
  • Break down the problem. What exactly doesn't work for you with command line arguments? Show a [mre], explain what you want to do, and what doesn't work. Don't include anything more than the actual bare minimum. – Cheatah May 11 '22 at 17:05
  • @rici no, not from the command line to function, it is the other way around – Hamzah Khan May 11 '22 at 17:15
  • when i run this function in a shell, the file is made and the output is printed, I don't want the output in the file but as a variable output, so I can store it in an array – Hamzah Khan May 11 '22 at 17:15
  • @Cheatah, I have confusion how and what to write to get a minimal reproducible example – Hamzah Khan May 11 '22 at 17:16
  • @hamzah: store it in an array where? – rici May 11 '22 at 18:12
  • @HamzahKhan If you don't show any work, I'm just gonna assume you haven't done any. Bye. – Cheatah May 11 '22 at 19:11
  • @HamzahKhan: if you want to extract information from a process, why are you listing links which are evidently about sending information to a process . That's good to read about, but it's completely irrelevant to your question. You should try reading the Bash manual, assuming that's the shell you use. – rici May 11 '22 at 19:19
  • I found the solution – Hamzah Khan May 16 '22 at 13:33
  • i had to write strncpy(fname_cs,"dev/null",400), in the code. the above picture i posted was a snippet but in the c file, i wrote these lines and than when ran the script from the shellm transfered the data to a variable before it got deleted. – Hamzah Khan May 16 '22 at 13:34

1 Answers1

0
strncpy(fname_cs,"dev/null",400)

had to write this line of code multiple times in the c file, so nothing is printed and than in the shell, i transferred the data to a variable before it is deleted.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 17 '22 at 20:55