Created
May 24, 2020 09:22
-
-
Save Developer1Dev/868a922c01debc75648607f527b3c145 to your computer and use it in GitHub Desktop.
C Programming, Arrays, Pointers, References, C++ Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In the following code coming from "The C Programming Language" of Kernighan and Ritchie, | |
we have an interesting insight, obvious, but still interesting to remind : even if the parameter s is not declared as a reference, | |
as it is allowed to be in C++, it acts as a reference. Indeed, what is behind an array in C Programming language, is a pointer. | |
*/ | |
int getline(char s[ ], int lim) | |
{ | |
int c,i; | |
for(i=0; i<lim-1 && (c=getchar())!=EOF && c!'\n';++i) | |
s[i]=c; | |
if(c='\n'){ | |
s[i]=c; | |
++i; | |
} | |
s[i]='\0'; | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment