hello everyone, im new in here and im having a headache with my program,the thing is that i need to get a input from the keyboard and then separate it using strtok but have to separate the tokens using 4 diferent cases and in each case i need to print the result and save it to a string like this:
input String : Label Instruction #50,Y; Label <with>
and the output should look like this:
Label: Label
Instruction: Instruction
Character 1: #50
Character 2: Y
Comentaries: Label <with>
also it has to be able to reconize if a instruction is missed like this:
Input String: adda
Output String
Label: -----
Instruction: adda
Character 1: -----
Comentaries: -----
i already got most of the problem but i still cant make the last if statement of "after finding a ; character" i would like to print Comentaries : (any token after a ;) but when i tryed to put it on a if alll i get is a new Character[i]:(anything after the ;) i have tryed for like 2 hrs and i dont know what else can i do to fix this cna some1 please help me?
heres my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
/*
* ||
*/
int main() {
char word[256];
fgets(word,256,stdin);
char *result;
while (result != NULL)
{
int i=0;
char delimit[]="\n , ;";
result=strtok (word,delimit);
if (word[0] != 32 && word[0] != 9)
{
printf("Label \"%s\"\n", result);
result = strtok (NULL, "\n , ;");
}
printf("Instruction \"%s\"\n", result);
result = strtok (NULL, "\n , ;");
for (i = 0; i < result; i++)
{
printf("Character [%d]\"%s\"\n",i, result);
result = strtok (NULL, ", ;");
}
if(word[0] == 59)
{
printf("Comentaries \"%s\"\n",result);
result = strtok (NULL, ";");
}
result = NULL;
}
return(0);
}