Last active
January 3, 2016 03:39
-
-
Save iamandrewluca/8403727 to your computer and use it in GitHub Desktop.
Making in a string from multiple dots one dot
This file contains 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> | |
#include <string.h> | |
int main(void) { | |
// your code goes here | |
char text[] = ".andrei... luca..varu.jora...a......sula....."; | |
char * ptext = text; | |
char * punct = "."; | |
int numarPuncte = 0; | |
int lungime = 0; | |
while ((ptext = strchr(ptext+1, punct[0]))) | |
{ | |
numarPuncte = strspn(ptext, punct); | |
if (numarPuncte != 1) | |
{ | |
lungime = strlen(ptext + numarPuncte); | |
strncpy(ptext + 1, ptext + numarPuncte, lungime); | |
ptext[lungime+1] = '\0'; | |
} | |
} | |
printf("%s", text); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment