0
Basically what I need is to make a mini Assembly simulator. the information will be entered by the user thus: MOV A,30
then what I was thinking of doing was storing the first 3 characters of the string in a new string (which in this case would be the first "MOV" command) and storing the part of "A,30" in another, to then separate this last string and get the other 2 commands, but when I type the command, only the first 3 characters (MOV) are shown in the print.
someone knows how I could make it work what I’m doing, or how I could just sort out the 3 pieces of information and store it, without the need to separate it?
Here is the basis of that code:
int main()
{
char comando[20];
char comando1[20];
char comando2[20];
char comando3[20];
scanf("%s", &comando);
memcpy(comando1, &comando[0], 3);
memcpy(comando2, &comando[3], strlen(comando));
printf("\n%s %s", comando1, comando2); // essa parte aq é só pra verificar se foi armazenado corretamente
return 0;
}
Just adding: if the beginning of your string does not have 3 characters you can break your string using the function
strtok
of<string.h>
.– anonimo
good, better than using Strtok to break in spaces is already read separate as I suggested at the end.
– vmp
For this specific case yes. I just wanted to draw attention to the fact that there is already a function to split a string into tokens.
– anonimo
I was doing this to read the 2 separate commands, but it wasn’t working either, so I figured it was because in typing the command there is no ENTER to differ from each other, only a space, so the program would read the 2 commands as only 1, The space would be read as one of the characters. obg for help!!
– user220443