Initial commit

This commit is contained in:
2021-10-01 20:24:05 +02:00
commit 860c025165
194 changed files with 4846 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Funktionsprototyp av isNumeric */
int isNumeric(const char *str);
int main(void)
{
char c[10];
float cels, f;
while(fgets(c, sizeof(c), stdin) != NULL)
{
if (isNumeric(c))
{
cels = atof(c); /* char till float (stdlib.h) */
f = cels*9/5+32;
printf("%.1f\n", f);
}
else
{
fprintf(stderr, "Påträffade icke-numeriskt värde\n");
return 1;
}
}
return 0;
}
/* Funktionen för att kontrollera inmatade tecken */
int isNumeric(const char *str)
{
if(strspn(str, "0123456789.-\n") == strlen(str)) /*string.h*/
{
return 1;
}
else
{
return 0;
}
}

15
kapitel14/fahr.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char c[10];
float cels, f;
while(fgets(c, sizeof(c), stdin) != NULL)
{
cels = atof(c); /* gör om char till float (stdlib.h) */
f = cels*9/5+32;
printf("%.1f\n", f);
}
return 0;
}

29
kapitel14/miljovar-ex1.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
/* Spara ett värde för senare användning */
const char* myhome = getenv("HOME");
/* Skriv ut några miljövariabler */
printf("Ditt UID är: %i\n", getuid());
printf("Ditt GID är: %i\n", getgid());
printf("Ditt användarnamn är: %s\n", getenv("USER"));
printf("Det aktuella programmet heter: %s\n", getenv("_"));
printf("Din hemkatalog är: %s\n", myhome);
/* Testa om en variabel är satt eller inte */
if (getenv("DISPLAY"))
{
printf("Du använder X-Window just nu\n");
}
else
{
printf("Du använder inte X-Window just nu\n");
}
return 0;
}

11
kapitel14/miljovar-ex2.c Normal file
View File

@@ -0,0 +1,11 @@
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
setenv("MINVAR", "J-B", 0); /* sätt variabeln (0 = skriv ej
över ev. befintlig variabel) */
printf("%s\n", getenv("MINVAR")); /* testa om det fungerade */
return 0;
}

8
kapitel14/outerrtest.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main(void)
{
fprintf(stdout, "Text till stdout\n");
fprintf(stderr, "Ett felmeddelande\n");
return 0;
}

5
kapitel14/temps.txt Normal file
View File

@@ -0,0 +1,5 @@
22
23
25
30
31

10
kapitel14/testtmp.txt Normal file
View File

@@ -0,0 +1,10 @@
id=151 temperature=-4.6 humidity=92 time=2016-11-13 22:50:20
id=167 temperature=22.1 humidity=20 time=2016-11-13 22:49:34
id=151 temperature=-4.6 humidity=92 time=2016-11-13 22:53:32
id=167 temperature=22.0 humidity=20 time=2016-11-13 22:53:34
id=151 temperature=-4.6 humidity=92 time=2016-11-13 22:56:44
id=167 temperature=22.3 humidity=20 time=2016-11-13 22:56:45
id=151 temperature=-4.7 humidity=92 time=2016-11-13 22:59:56
id=167 temperature=22.4 humidity=20 time=2016-11-13 22:59:57
id=151 temperature=-4.7 humidity=92 time=2016-11-13 23:02:20
id=167 temperature=22.4 humidity=20 time=2016-11-13 23:02:21