Preface: this is not a homework question. However, my teacher gave us a review packet with some C coding, and for some reason none of the C programs are compiling. First I compiled them from the shell, then I used a compiler to see if something was wrong with compiling from a shell. Both produced the same results... they'll compile and execure, but there's no out put. Here is an example of some of the code examples:
/* Character Arrays
Read a set of text lines and print the longest
*/
#include <stdio.h>
#define MAXLINE 1000
int getline(char [],int);
void copy(char [], char []);
int getline(char s[], int limit) {
int c, i;
for (i=0; i<(limit - 1) && (c=getchar())!=EOF
&& c != '\n'; i++)
s = c;
if (c == '\n') {
s = c;
i++;
}
s = '\0';
return i;
}
void copy(char to[], char from[]) {
int i=0;
while ((to = from) != '\0')
i++;
}
int main() {
int len, max;
char line[MAXLINE], longest[MAXLINE];
max = 0;
while ((len = getline(line,MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest,line);
}
if (max > 0)
printf("%s",longest);
}
#include <stdio.h>
int main () {
long nc = 0;
while (getchar() != EOF)
nc++;
printf("%ld\n",nc);
return 0;
}
Is there something I'm doing wrong here.... ?
Thanks