Question: Rewrite appropriate programs with pointers instead of array indexing: getline() atoi() itoa() strindex() Please write separate codes for all four with spaces in between. 1

Rewrite appropriate programs with pointers instead of array indexing:
getline()
atoi()
itoa()
strindex()
Please write separate codes for all four with spaces in between.
 Rewrite appropriate programs with pointers instead of array indexing: getline() atoi()
itoa() strindex() Please write separate codes for all four with spaces in
between. 1 #include 2 3 int getline_(char s[], int lim); 4 int
getline_ptr(char* s, int lim); 5 6 int main() 7 { 8 char

1 #include 2 3 int getline_(char s[], int lim); 4 int getline_ptr(char* s, int lim); 5 6 int main() 7 { 8 char s[100]; 9 getline_ptr(s, 100); 10 printf("%s",s); 11 12 return 0; 13 } 14 15 int getline_(char s[], int lim){ 16 int c, i; 17 i=0; 18 while(--lim >0 && (c=getchar()) != EOF && c != ' ') 19 s[i++] = c; 20 if (c == ' ') 21 s[i++] = 0; 22 s[i] = '\0'; 23 24 return i; 25 } 26 27 //REWRITE WITH POINTERS 28 int getline_ptr(char* s, int lim){ 29 return 0; 30 ] 1 include 2 #include 3 4 int ato (char s[]); 5 int atoi_ptr(char *s); 6 7 int main() 8.{ 9 char n[] ="255"; 10 printf("%d ", atoi_ptr(n)); 11 12 return 0; 13 } 14 15. int atoi (char s[]){ 16 int i, n, sign; 17 18 for (i=0; isspace(s[i]); i++) 19 ; sign = (s[i] == '-') ? -1 : 1; 21 if (s[i] = '+' || s[i] == '-') 22 i++; 23 for (n =0; isdigit(s[i]); i++) 24 n 10 * n + (s[i] - '0'); 25 return sign *n; 26 } 27 28 - int atoi_ptr(char *s){ 29 30 // YOUR CODE HERE 31 return 0; 32 } 20 1 #include 2 3 void itoa(int n, char s(); 4 void itoa_ptr(int n, chars); 5 void reverse(char s(); 6 7 int maino 8-{ 9 char s[10]; 10 11 itoa(255, s); 12 print("%s",s); 13 14 return 0; 15} 16 itoa: convert n to characters in s */ 17 void itoa(int n, char s[]){ 18 int i, sign; 19 20 if((sign=n) 0); 26 if (sign 35 - void reverse(char s[]){ 36 int c, i, j; 37 38 for (i=0, j = strlen(s)-1; i 2 3 int strindex (char s[], char t[]); 4 int strindex_ptr (char *s, char *t); 5 6 int main() 7 - { 8 printf("%d", strindex("Hello World", "World")); 9 return 0; 10 } 11 12 int strindex(char s[l, char t[]){ 13 int i, j, k; 14 15 for (i=0; s[i] != '\0'; i++){ 16 for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++) 17 ; 18 if (k>0 && t[k] '\0') 19 return i; 20 } 21 22 return -1; 23 } 24 25 int strindex_ptr (char *s, char *t){ 26 // YOUR CODE HERE 27 return -1; 28 } } mo

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!