From previous threads, I know that you can achieve this by using the method shown here: How do you allow spaces to be entered using scanf?
It works in Main but when I put it inside a function, it doesn't work.
This is my code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void dataInput();
struct record {
char title[50];
char author[50];
char category[20];
float price;
};
struct record info[500];
void main(){
dataInput();
}
void dataInput(){
int x;
for(x = 0; x <= 10; x++ ){
scanf("%s", &info[x].title);
printf("%s\n", &info[x].title);
}
}
Output:
If I use regex:
scanf("%50[0-9a-zA-Z ]s", &info[x].title);
Output:
Hmm whats wrong here