feat(assign1): add employee.c
This commit is contained in:
parent
0122c877ac
commit
eb87fd068d
2 changed files with 48 additions and 5 deletions
34
assign1/c-programs/employee.c
Normal file
34
assign1/c-programs/employee.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// Character array to store name
|
||||||
|
// In C, strings are arrays of characters ending with '\0'
|
||||||
|
char name[50];
|
||||||
|
int employee_id;
|
||||||
|
float hours_worked;
|
||||||
|
|
||||||
|
printf("OwlTech Employee Registration\n");
|
||||||
|
printf("=============================\n");
|
||||||
|
|
||||||
|
printf("Enter your name: ");
|
||||||
|
// fgets reads a line including spaces
|
||||||
|
// stdin means "standard input" (keyboard)
|
||||||
|
fgets(name, sizeof(name), stdin);
|
||||||
|
|
||||||
|
// Remove newline that fgets includes
|
||||||
|
name[strcspn(name, "\n")] = '\0';
|
||||||
|
|
||||||
|
printf("Enter your employee ID: ");
|
||||||
|
// & means "address of" - scanf needs to know where to store the value
|
||||||
|
scanf("%d", &employee_id);
|
||||||
|
printf("Hours worked this week: ");
|
||||||
|
scanf("%f", &hours_worked);
|
||||||
|
|
||||||
|
printf("\nEmployee Summary:\n");
|
||||||
|
printf("Name: %s\n", name); // %s for string
|
||||||
|
printf("ID: %d\n", employee_id); // %d for integer
|
||||||
|
printf("Hours: %.2f\n", hours_worked); // %.2f for float with 2 decimals
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,21 @@
|
||||||
{
|
let
|
||||||
assign1-hello = { stdenv }:
|
basic-c = name: { stdenv }:
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "hello";
|
inherit name;
|
||||||
src = ./.;
|
src = ./.;
|
||||||
buildPhase = "gcc c-programs/hello.c -o hello";
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
gcc c-programs/${name}.c -o ${name}
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
install hello $out/bin/hello
|
install ${name} $out/bin/
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
in {
|
||||||
|
assign1-hello = basic-c "hello";
|
||||||
|
assign1-employee = basic-c "employee";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue