Commit 94317caf authored by Alan Marchiori's avatar Alan Marchiori
Browse files

Lec 1 (cintro) import

parents
# CSCI 206 Computer Organization & Programming
# Makefile for the introduction to C lectures
#
# Author: L. Felipe Perrone
# Date: 2011-08-24
#
# Copyright (c) 2011 Bucknell University
#
# Permission is hereby granted, free of charge, to any individual or
# institution obtaining a copy of this software and associated
# documentation files (the "Software"), to use, copy, modify, and
# distribute without restriction, provided that this copyright and
# permission notice is maintained, intact, in all copies and supporting
# documentation.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL BUCKNELL UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
CFLAGS = -std=gnu99 -Wall -g
EXECS = first second third fourth fifth sixth seventh eighth ninth thirdA thirdB thirdC
all: $(EXECS)
first: first.c
gcc $(CFLAGS) first.c -o first
second: second.c
gcc $(CFLAGS) second.c -o second
third: third.c
gcc $(CFLAGS) third.c -o third
thirdA: thirdA.c
gcc $(CFLAGS) thirdA.c -o thirdA
thirdB: thirdB.c
gcc $(CFLAGS) thirdB.c -o thirdB
thirdC: thirdC.c
gcc $(CFLAGS) thirdC.c -o thirdC
fourth: fourth.c
gcc $(CFLAGS) fourth.c -o fourth
fifth: fifth.c
gcc $(CFLAGS) fifth.c -o fifth
sixth: sixth.c
gcc $(CFLAGS) sixth.c -o sixth
seventh: seventh.c
gcc $(CFLAGS) seventh.c -o seventh
eighth: eight.c
gcc $(CFLAGS) eighth.c -o eighth
ninth: ninth.c
gcc $(CFLAGS) ninth.c -o ninth
clean:
/bin/rm -rf $(EXECS)
#include <stdio.h>
int main(int argc, char* argv[]) {
float pi = 3.1415926;
char *pf = (char*) &pi;
int i;
printf("pi= %f\n\n", pi);
for (i=0; i<4; i++) {
printf("pf[%d]= %x\n", i, pf[i]);
}
}
#include <stdio.h>
int main(int argc, char* argv[]) {
char error_message[] = "Something evil happened.";
printf("%s\n", error_message);
error_message[10] = 'g';
error_message[11] = 'o';
error_message[12] = 'o';
error_message[13] = 'd';
printf("%s\n", error_message);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
printf("hello C world\n");
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i, j;
j=0;
for (i=0; i<100; i++) {
j += i;
}
printf("i= %d, j= %d\n\n", i, j);
i=0; j=0;
while (i<100) {
j += i;
i++;
}
printf("i= %d, j= %d\n\n", i, j);
i=0; j=0;
do {
j += i;
i++;
} while (i<100);
printf("i= %d, j= %d\n\n", i, j);
}
#include <stdio.h>
#include <stdlib.h>
char *str1;
char str2[20] = "hello dufus!";
int main(int argc, char* argv[]) {
printf("str1= %pn", str1);
str1 = malloc(40);
printf("str1= %p\n", str1);
printf("str2= %p\n", str2);
printf("&str2= %p\n", &str2);
printf("&(str2[0])= %p\n", &(str2[0]));
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 7;
double x = 3.1415926;
char c = 'w';;
printf("%d, %c, %lf\n",i, c, x);
}
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i;
char p[] = "This is a test.";
for (i=0; i<strlen(p); i++) {
printf("%c", p[i]);
}
printf("\n\n");
printf("string starting at p= %s\n", p);
printf("content of p= %p\n\n", p);
char *s = p;
printf("string starting at s= %s\n", s);
printf("length= %d\n", (int) strlen(s));
printf("s[5]= %c\n", s[5]);
printf("*(s+6)= %c\n\n", *(s+6));
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 7;
int j = -1;
int* pi = &i;
int* pj = &j;
printf(" i = %d\n", i);
printf(" j = %d\n", j);
printf(" pi= %p\n", pi);
printf(" pj= %p\n", pj);
printf(" data pointed to by pi= %d\n", *pi);
printf(" data pointed to by pj= %d\n\n", *pj);
*pi = 6;
pj = pi - 1;
printf(" i = %d\n", i);
printf(" j = %d\n", j);
printf(" pi= %p\n", pi);
printf(" pj= %p\n", pj);
printf(" data pointed to by pi= %d\n", *pi);
printf(" data pointed to by pj= %d\n\n", *pj);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
{
int i = 999;
int j = 666;
printf("i= %d, j= %d\n", i, j);
{
int i = 123;
int j = i*i;
printf("i= %d, j= %d\n", i, j);
}
printf("i= %d, j= %d\n", i, j);
}
}
#include <stdio.h>
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
int main(int argc, char* argv[]) {
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
static int i = 7;
float x = 2.71828;
static double y = 3.1415926;
char c = 'w';
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment