im trying to separate words from a sting, whem the code replaces the space for the ' \0' i need to increment the "pos" so i can continue read the array the code so far is this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
void separa_pal(char text[]);

int main(int argc, char** argv)
{
    char text[MAX] = "hello my darling";
    printf("text: %s \n", text);
    separa_pal(text);
    printf("%s\n", text);
}

void separa_pal(char text[])
{
    int i = 0;
    int pos = 0;
    pos = text[i]; //the problem is here
    while(text[i] != '\0')
    {
        if(text[i] == ' ')
        {
                text[i] = '\0';
                pos = text[i + 1]; // and here
            }else{
                i++;
            }
    }
}

btw i know of strtok but i need to do it without pointers so if you guys can help me i would apreciate it :)

Whenever you define a string as

char str[]="Hello\0MIster\0HowAre You?";
printf("%s",str);

Every time the compiler stops outputing the characters of the string to the output console once it encounters a '\0' character.So even if you put '\0' character in place of ' ' character this won't do any good.
Instead you can use an array of character arrays and store every generated string in order.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.