i am posting two programs.The first one is test3.c which is inputing students name and marks.In this one ,the function is getting input correctly but the result is not reflected in the main function.Dont know why.
In the second one(1_5.c) m unable to replace the spaces in my programs by %20.suppose i enter 'ankur modi' it shud print 'ankur%20modi'.Why this isnt workin.Please modify the programs for error and do let me know the errors you encountered
PSlease tell me whats wrong with my implementation or concept
test3.c
-----------------------------------------------------------------------------------------------------------------Code:#include<stdio.h> #include<stdlib.h> #include<string.h> #define STUDENTS 2 #define SUBJECTS 3 int main() { int i,j; char name[STUDENTS][20]={'\0'}; int marks[STUDENTS][SUBJECTS+1]={0}; inputmarks(name,marks); for(i=0;i<STUDENTS;i++) { printf("\n%s\n",name[i]); //here its not displaying correct for(j=0;j<SUBJECTS;j++) { printf("%d\n",marks[i][j]); } } return 0; } inputmarks(char *string[STUDENTS],int arr[][SUBJECTS+1]) { int i,j,(*mrks)[SUBJECTS+1]=arr; for(i=0;i<STUDENTS;i++) { string[i]=(char *)malloc(20*sizeof(char)); printf("enter name"); scanf("%s",string[i]); printf("\nEnter mrks of %d subjects",SUBJECTS); for(j=0;j<SUBJECTS;j++) { scanf("%d",&(*(mrks+i))[j]); } } //shows that the names are getting stored in the string array for(i=0;i<STUDENTS;i++) { printf("------------------------------\n%s\n-----------------------------",string[i]); } return 0; }
1_5.c
Code:#include<stdio.h> #include<stdlib.h> #include<string.h> void edit(char *,int); int main() { char *stri; int k; stri=(char *)malloc(sizeof(char)); printf("enter string"); scanf("%[^\n]",stri); k=strlen(stri); edit(stri,k); printf("%s\n",stri); return 0; } void edit(char *str,int len) { int newlen=0,count=0; int i; while(*str) { if(*str++ ==' ') { count++; } } printf("%d",count); newlen=len+2*count; printf("%d",newlen); str[newlen]='\0'; for(i=len-1;i>=0;i--) { //printf("%d",i); if(str[i]==' ') { //printf("=--------------"); str[newlen-1]='0'; str[newlen-2]='2'; str[newlen-3]='%'; newlen=newlen-3; } else { str[newlen-1]=str[i]; //printf("%s\n",str); newlen=newlen-1; } } //printf("----------%s",str); }