Skip to content

Instantly share code, notes, and snippets.

@Developer1Dev
Created May 24, 2020 09:22
Show Gist options
  • Save Developer1Dev/868a922c01debc75648607f527b3c145 to your computer and use it in GitHub Desktop.
Save Developer1Dev/868a922c01debc75648607f527b3c145 to your computer and use it in GitHub Desktop.
C Programming, Arrays, Pointers, References, C++ Programming
/*
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