[SPCA] Restructure, intro to C continued

This commit is contained in:
2026-01-05 16:48:36 +01:00
parent 4a02e20218
commit 433111833c
16 changed files with 154 additions and 9 deletions

View File

@@ -1,9 +1,11 @@
#include "01_func.h"
#include <stdio.h>
int get_user_input_int( char prompt[] ) {
int input_data;
printf( "%s", prompt ); // Always wrap strings like this for printf
scanf( "%d", &input_data ); // Get user input from CLI
printf( "%s", prompt ); // Always wrap strings like this for printf
scanf( "%d", &input_data ); // Get user input from CLI
int input_data_copy = input_data; // Value copied
// If statements just like any other language
if ( input_data )
@@ -11,6 +13,7 @@ int get_user_input_int( char prompt[] ) {
else
printf( "Input is zero" );
// Switch statements just like in any other language
switch ( input_data ) {
case 5:
printf( "You win!" );
@@ -21,17 +24,20 @@ int get_user_input_int( char prompt[] ) {
printf( "No win" ); // Case for any not covered input
}
int input_data_copy = input_data;
while ( input_data > 1 ) {
input_data -= 1;
printf( "Hello World\n" );
}
// Inversed while loop (executes at least once)
do {
input_data -= 1;
printf( "Bye World\n" );
if ( input_data_copy == 0 )
goto this_is_a_label;
} while ( input_data_copy > 1 );
this_is_a_label:
printf( "Jumped to label" );
return 0;
}