CSC 357 Lecture Notes Week 3
Leftovers from Week 2 Notes; Additional C Language and Library
Features
FILE* fopen(char* name, char* mode);
#define getchar() getc(stdin) #define putchar() putc(stdout)
See the man pages for each for further discussion, including what the return values are used for.int fscanf(FILE* fp, char* format, ...) int fprintf(FILE* fp, char* format, ...)
fprintf(stderr, "%s: No such file or director", filename);
If successful, it returns the filled line, a null pointer otherwise.char* fgets(char* line, int maxline, FILE* fp)
If successful, it returns the number of chars output, EOF otherwise.int fputs(char* line, FILE* fp)
static int i;
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
char s[20];
char* f(char* s1, char* s2, int* ip) {
    char* s3;
    s3 = strcat(s1, s2);
    strcpy(s, s3);
    *ip = strlen(s3);
    return s3;
}
void main() {
    char s1[20] = "abcdef";
    char* s2 = strcpy((char*) malloc(strlen("ghijklmn")), "ghijklmn");
    char* s3;
    int i;
    s3 = f(s1, s2, &i);
    free(s2);
    printf("s=%s, s3=%s, length of s=%d, length of s3=%d0, s, s3, strlen(s), i);
    printf("sizeof(s)=%d, sizeof(s3)=%d0, sizeof(s), sizeof(s3));
}