Moon Light Box

Time is Money

Posts match “ string ” tag:

C - Delete Space of String

| Comments

#include <stdio.h>
#include <stdlib.h>

void delete_space(char *s1, char *s2)
{
    while(*s1 != NULL)
    {
        if(!isspace(*s1))
        {
            *s2 = *s1;
            s2++;
        }
        s1++;
    }
    *s2 = '\0';
}

int main(int argc, char *argv[])
{
    char buf[80], buf1[80];

    int i;

    printf("Please input a string\n");

    gets(buf);

    delete_space(buf, buf1);

    printf("The result of delete space from string\n");

    puts(buf1);

    system("PAUSE");

    return 0;
}

C - Reverse String

| Comments

#include <stdio.h>
#include <string.h>

void reverse(char* str)
{
    int i, j;
    char c;
    for(i = 0, j = strlen(str)-1; i<j; ++i, --j)
        c = str[i], str[i] = str[j], str[j] = c;
}

int main()
{
    char str[] = "ABCDE";
    reverse(str);
    puts(str);
    return 0;
}