| PREV |
Programs |
NEXT |
| |
(74 / 301) * |
|
|
|
|
Write a simple piece of code to split a string at equal intervals
|
Suppose you have a big string
This is a big string which I want to split at equal intervals, without caring about the words.
Now, to split this string say into smaller strings of 20 characters each, try this
#define maxLineSize 20
split(char *string)
{
int i, length;
char dest[maxLineSize + 1];
i = 0;
length = strlen(string);
while((i+maxLineSize) <= length)
{
strncpy(dest, (string+i), maxLineSize);
dest[maxLineSize - 1] = '\0';
i = i + strlen(dest) - 1;
printf("\nChunk : [%s]\n", dest);
}
strcpy(dest, (string + i));
printf("\nChunk : [%s]\n", dest);
}
|
| PREV |
COMMENTS INDEX PRINT |
NEXT |
Last updated:
November 3, 2005
www.cracktheinterview.com - Your destination for the most common IT interview questions, answers, frequently asked interview questions (FAQ), C Programs, C Datastructures for technical interviews conducted by the top IT companies around the world!
|
|
|