-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBeginners_-_String_functions.c
70 lines (54 loc) · 2.69 KB
/
Beginners_-_String_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "raylib.h"
// string.h
// for strlen()=length of string, strcmp()=compare two strings,
// strlwr()=convert string to lower case, strupr()=convert string to upper case.
#include "string.h"
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example.");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
char lenny[10] = "hello";
char com1[] = "abc";
char com2[] = "abc";
char com3[] = "abcd";
char lower[] = "IsThisLow?";
char higher[] = "IsThisHigh?";
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(FormatText("Length of lenny is : %i",strlen(lenny)),100,200,20,DARKGRAY);
// strlen returns the amount of characters in the char.
if(strcmp(com1,com2)==0){
DrawText("chars com1 and com2 have same contents.",100,220,20,DARKGRAY);
}else{
DrawText("chars com1 and com2 do not have same contents.",100,220,20,DARKGRAY);
}
if(strcmp(com1,com3)==0){
DrawText("chars com1 and com2 have same contents.",100,240,20,DARKGRAY);
}else{
DrawText("chars com1 and com2 do not have same contents.",100,240,20,DARKGRAY);
}
// with strcmp it returns <0 or >0 if the char is different. ==0 if the same.
DrawText(FormatText("char lower in lower case is : %s",strlwr(lower)),100,260,20,DARKGRAY);
DrawText(FormatText("char higher in higher case is : %s",strupr(higher)),100,280,20,DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}