I am trying to separate date/month/year from a string into multiple variables. When I try to print them I get unknown symbols.
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
char string[40];
char tempm[10], tempd[10], tempy[10];
int month, date, year;
int count = 0;
printf("Introduceti data: \n");
scanf(" %[^\n]s", string);
for (int i = 0; i <strlen(string); i++){
if (string[i] == '/'){
count ++;
}
else{
if (count == 0){
strncat(tempm, &string[i], 1);
}
if (count == 1){
strncat(tempd, &string[i],1);
}
if (count == 2){
strncat(tempy, &string[i], 1);
}
}
}
printf("%s",tempm);
}
And this is the output:
Introduceti data:
11/12/21
Y��U11
How to delete 'Y��U'?