Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Last active January 3, 2016 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamandrewluca/8403727 to your computer and use it in GitHub Desktop.
Save iamandrewluca/8403727 to your computer and use it in GitHub Desktop.
Making in a string from multiple dots one dot
#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