Skip to content

Instantly share code, notes, and snippets.

@kYroL01
Created September 2, 2016 10:52
Show Gist options
  • Save kYroL01/52f4ba3a761bb6bd499635ab93d05d85 to your computer and use it in GitHub Desktop.
Save kYroL01/52f4ba3a761bb6bd499635ab93d05d85 to your computer and use it in GitHub Desktop.
Given a string, for every char (digit or alphabet) print the string from begin and end of every single element
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/**
* Given a string, print subsequents for every chars
* i.e D4b = ABCD01234ab
**/
int main()
{
char S[101];
int len;
int i;
fgets(S, 101, stdin);
len = strlen(S);
S[len-1]= '\0';
len--;
char *p = S;
while(*p != '\0') {
if(*p >= 48 && *p <= 57) {
for(i=48; i<=*p; i++)
printf("%c", i);
}
else if(*p >= 65 && *p <= 90) {
for(i=65; i<=*p; i++)
printf("%c", i);
}
else if(*p >= 97 && *p <= 122) {
for(i=97; i <=*p ; i++)
printf("%c", i);
}
else {
printf("Value not valid\n");
return -1;
}
p++;
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment