In C, how can I create an error if no arguments are given on the command line? I do not use int main(int argc , * char[] argv). I have no input, so I get my variable withscanf("%d", input)
int main(int argc , * char[] argv)
scanf("%d", input)
Based on the code:
#include <stdio.h> int main() { int input; int rc = scanf("%d", &input); }
We can verify that we were scanf()able to successfully get some input from the user by checking its return value. Only when the rc == 1user correctly gave us a valid input.
scanf()
rc == 1
If you want to know more, I recommend reading the scanf documentation .
: , main argc argv.
main
argc
argv
main , :
int main(int argc, char *argv[])
, arc 1. :
arc
1
int main(int argc, char *argv[]) { if (argc < 2) { printf("error: missing command line arguments\n"); return 1; } ... }
main int main(void), . .
int main(void)
, main :
, , argc ( ) ; -)
int main(), .
int main()
Source: https://habr.com/ru/post/1628735/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1628730/why-roslyn-analyzers-needs-to-be-portable-assemblies&usg=ALkJrhjXJ--yD47gOnVC6N3xUylImJNcLwUnity 5: automatically detect a list of triangles for grid vertices - unity3dForcing a TCP socket to a specific window size - socketsAlgorithms for calculating the distance between two lines - pythonTwo functions, one generator - pythonC # While Loop vs For Loop? - c #ownCloud Downgrade not supported after apt-get update - upgradegetAvailableBlocksLong () * getBlockSizeLong () VS getAvailableBytes () - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1628739/how-does-npm3-decides-to-install-flat-vs-nested&usg=ALkJrhh9xdTz5-sw_YHNx-Ng-kS9sZUsVwERR trap only works once? - bashAll Articles