c - Need to change the Pointers make me problems -
hello have program receiving parameters user. transmission performed using pointers. code later not use pointers creates problem received. happy if me fix code work.
code -
#include <stdlib.h> #include<string.h> void order(int n,char argv[99]); int main(int argc, char** argv) { int i,n; n = argc; order(n,*argv); } void order(int n,char argv[99]) { int i,j; char temp; for(i=1; < n; i++) { for(j = 0 ; j < n - 1; j++) { if(argv[j] > argv[j+1]) { temp=argv[j]; argv[j]=argv[j+1]; argv[j+1]=temp; } } } system("pause"); (i = 0; < n ; i++) { printf("%c",argv[i]); } }
it appears confused argc
, argv
.
int argc
contains number of command-line arguments passed program, char **argv
array (null-pointer terminated even) of strings (null-byte terminated character arrays) containing these arguments. @ odds program:
1. there no reason limit length of 1 command-line argument 99 characters.
2. pass first (zero-indexed) command-line argument order()
. name of program.
3. use argc
in order()
. however, argc
not length of first command-line argument. strlen(argv[0])
.
Comments
Post a Comment