Created
October 8, 2014 17:06
-
-
Save szilardhuber/fef26c15556e20ceea07 to your computer and use it in GitHub Desktop.
c tutorial :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int is_number(char c) | |
{ | |
return c >= '0' && c <= '9'; | |
} | |
int difference() | |
{ | |
return 'A' - 'a'; | |
} | |
int main(int argc, char** argv) | |
{ | |
char* argument; | |
int i; | |
int non_numeric_character_index; | |
if (argc != 2) | |
{ | |
printf("Usage: lowercase <string>\n"); | |
return 0; | |
} | |
argument = argv[1]; | |
non_numeric_character_index = 0; | |
for (i = 0; argument[i] != 0 ; i++) | |
{ | |
if (!is_number(argument[i])) | |
{ | |
argument[non_numeric_character_index++] = argument[i]; | |
} | |
} | |
argument[non_numeric_character_index] = 0; | |
printf("%s\n", argument); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char is_uppercase_letter(char c) | |
{ | |
return c >= 'A' && c <= 'Z'; | |
} | |
char difference() | |
{ | |
return 'a' - 'A'; | |
} | |
int main(int argc, char** argv) | |
{ | |
char* argument; | |
int i; | |
if (argc != 2) | |
{ | |
printf("Usage: %s <string>\n", argv[0]); | |
return 0; | |
} | |
argument = argv[1]; | |
for (i = 0; argument[i] != 0 ; i++ ) | |
{ | |
if (is_uppercase_letter(argument[i])) | |
{ | |
argument[i] = argument[i] + difference(); | |
} | |
// printf("%d\n", argument[i]); | |
} | |
printf("%s\n", argument); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char is_ended(char* str, int i) | |
{ | |
return str[i] == 0; | |
} | |
int main(int argc, char** argv) | |
{ | |
if (argc != 3) | |
{ | |
printf("Usage: string_compare <string1> <string2>\n"); | |
return 0; | |
} | |
char* str1 = argv[1]; | |
char* str2 = argv[2]; | |
for (int i = 0 ; ; i++) | |
{ | |
if (is_ended(str1, i)) | |
{ | |
if (is_ended(str2, i)) | |
{ | |
printf("Equal length\n"); | |
return 0; | |
} | |
else | |
{ | |
printf("Str1 is shorter.\n"); | |
return 0; | |
} | |
} | |
if (is_ended(str2, i)) | |
{ | |
printf("str2 is shorter\n"); | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment