Initial commit
This commit is contained in:
17
kapitel19/felsok-ex1.c
Normal file
17
kapitel19/felsok-ex1.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x;
|
||||
int y = 5;
|
||||
|
||||
char text[20] = "Hejsan";
|
||||
|
||||
for (x = 1; y < 100; x++)
|
||||
{
|
||||
y = (y*3)-x;
|
||||
}
|
||||
printf("%s\n", text);
|
||||
|
||||
return 0;
|
||||
}
|
25
kapitel19/felsok-ex2.c
Normal file
25
kapitel19/felsok-ex2.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
float circum(float d);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
float di;
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s diamater\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
di = atof(argv[1]);
|
||||
printf ("Circumference of a circle with a diamater %.2f is"
|
||||
" %.2f\n", di, circum(di));
|
||||
return 0;
|
||||
}
|
||||
|
||||
float circum(float d)
|
||||
{
|
||||
float pi = 3.14159265;
|
||||
return (pi*d);
|
||||
}
|
23
kapitel19/flt-fel1.c
Normal file
23
kapitel19/flt-fel1.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *say(char namn[]);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *mening = say("Jack-Benny");
|
||||
printf("%s\n", mening);
|
||||
free(mening);
|
||||
printf("Lisa hojtar: %s\n", mening);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *say(char namn[])
|
||||
{
|
||||
char *str;
|
||||
str = calloc(50, sizeof(char));
|
||||
strncat(str, "Hej ", 4);
|
||||
strncat(str, namn, 45);
|
||||
return str;
|
||||
}
|
14
kapitel19/leak1.c
Normal file
14
kapitel19/leak1.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char* buffer;
|
||||
buffer = malloc(sizeof(char)*15);
|
||||
*buffer = '\0';
|
||||
strcpy(buffer, "Hejsan svejsan");
|
||||
printf("%s\n", buffer);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
11
kapitel19/oinitialiserat-ex1.c
Normal file
11
kapitel19/oinitialiserat-ex1.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char* str;
|
||||
strcat(str, "Hej alla");
|
||||
printf("%s\n", str);
|
||||
return 0;
|
||||
}
|
17
kapitel19/undersoka-minne.c
Normal file
17
kapitel19/undersoka-minne.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *a;
|
||||
a = malloc(10*sizeof(char));
|
||||
*a = '\0';
|
||||
strcpy(a, "Hej hej");
|
||||
printf("Strängen %s\n", a);
|
||||
*a = '\0';
|
||||
printf("Strängen %s\n", a);
|
||||
|
||||
free(a);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user