Question: Rewrite appropriate C language programs WITH POINTERS instead of array indexing: 1) getline(), 2) atoi(), ********************************************************************************* 1) getline() #include int getline_(char s[], int lim); int

Rewrite appropriate C language programs WITH POINTERS instead of array indexing:

1) getline(),

2) atoi(),

*********************************************************************************

1) getline()

#include

int getline_(char s[], int lim); int getline_ptr(char* s, int lim);

int main() { char s[100]; getline_ptr(s,100); printf("%s",s);

return 0; }

int getline_(char s[], int lim){ int c, i; i=0; while(--lim >0 && (c=getchar()) != EOF && c != ' ') s[i++] = c; if (c == ' ') s[i++] = c; s[i] = '\0'; return i; }

//YOUR CODE HERE/ REWRITE WITH POINTERS int getline_ptr(char* s, int lim){ return 0; } ...

*********************************************************************************

2) atoi()

#include #include

int atoi(char s[]); int atoi_ptr(char *s);

int main() { char n[] ="255"; printf("%d ", atoi_ptr(n));

return 0; }

int atoi(char s[]){ int i, n, sign; for (i=0; isspace(s[i]); i++) ; sign = (s[i] == '-') ? -1 : 1; if (s[i] == '+' || s[i] == '-') i++; for (n =0; isdigit(s[i]); i++) n = 10 * n + (s[i] - '0'); return sign *n; }

int atoi_ptr(char *s){ // YOUR CODE HERE/ REWRITE WITH POINTERS return 0; } ...

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!