Created
January 16, 2020 14:05
-
-
Save Estecka/e91dbe1f2beaf46b7d12f4921748269f to your computer and use it in GitHub Desktop.
Converts the first few characters of a string into an int, for easier comparison.
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
/* ************************************************************************** */ | |
/* */ | |
/* ::: :::::::: */ | |
/* .stringToInt.c :+: :+: :+: */ | |
/* +:+ +:+ +:+ */ | |
/* By: abaur <[email protected]> +#+ +:+ +#+ */ | |
/* +#+#+#+#+#+ +#+ */ | |
/* Created: 2020/01/16 14:15:40 by abaur #+# #+# */ | |
/* Updated: 2020/01/16 14:25:04 by abaur ### ########.fr */ | |
/* */ | |
/* ************************************************************************** */ | |
#include <ctype.h> | |
#include <stdio.h> | |
int stringToInt(char* line) | |
{ | |
int result = 0; | |
for(int i=0; i<4; i++) | |
{ | |
if (!line[i]) | |
break; | |
result |= line[i] << (i * 8); | |
} | |
return result; | |
} | |
int main(int argc, char **args) | |
{ | |
for (int i=1; i<argc; i++) | |
printf ("%-4s %d\n", args[i], stringToInt(args[i])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment