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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started