Last active
June 24, 2018 14:31
-
-
Save DamianSuess/c60d4f2d1517814b19e4e52a4da82180 to your computer and use it in GitHub Desktop.
C string functions from VB6 commands
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
// 2006 - DS | |
#include "windows.h" | |
#include "stdio.h" | |
char *Mid(char *str, int start, int length); | |
char *Left(char *str, int length); | |
char *Right(char *str, int length); | |
int Asc(char *str); | |
char Chr(int value); | |
void main() | |
{ | |
//Example of usage: | |
printf("%s\n\n",Mid("i love c++", 2, 4)); //Output: love | |
printf("%s\n\n",Right("i love c++", 3)); //Output: c++ | |
printf("%s\n\n",Left("i love c++", 1)); //Output: i | |
printf("%i", Asc("A"));//Output: 65 | |
printf("%c", Chr(65));//Output: A | |
} | |
char *Mid(char *str, int start, int length) | |
{ | |
char *f; | |
f = (char*)malloc(length); //Allocate space in f | |
if (f==NULL) printf("Error allocating memory\n"); | |
strncpy(f, str+start, length); //Copy from 'start' characters of str to 'length'characters of str in f | |
f[length] = '\0'; //And add the end of the string | |
return f; | |
} | |
char *Left(char *str, int length) | |
{ | |
char *f; | |
f = (char*)malloc(length); | |
if (f==NULL) printf("Error allocating memory\n"); | |
strncpy(f,str, length); | |
f[length] = '\0'; | |
return f; | |
} | |
char *Right(char *str, int length) | |
{ | |
char *f; | |
f = (char*)malloc(length); | |
if (f==NULL) printf("Error allocating memory\n"); | |
strncpy(f, str+(strlen(str)-length), length); | |
f[length] = '\0'; | |
return f; | |
} | |
int Asc(char *str) | |
{ | |
char a; | |
a = str[0]; | |
return a; | |
} | |
char Chr(int value) | |
{ | |
char a; | |
a = value; | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment