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 :)