我正在开发一个数据库基础项目 考虑一个结构
i am working on a database basic project consider a structure
struct student { int rollno; char full_name[20]; char address[50]; char birthmark[50]; };如何获取此输入 rollno 6 名字john snow 地址winterfell of north 胎记剑全部伤害 什么我试过了: i尝试过scanf(%s,stringname),scanf(%[^ \ n] s,stringname ),获取(stringname), fgets(缓冲区,大小,标准差)与fflush stdin。 总有一些错误。 so far fgets工作得很好但是我读过ffush(stdin)是一种错误的做法。 所以应该同时输入字符串(带空格)的方法在另一个之后
how to take this input rollno 6 name john snow address winterfell of north birthmark swords wound all over What I have tried: i have tried scanf("%s",stringname),scanf("%[^\n]s",stringname),gets(stringname), fgets(buffer,size,stdin) with fflush stdin. there are always some error. so far fgets work perfectly but i have read ffush(stdin) is a wrong practice . so what should be the approach to take input of string (with spaces) simultaneously one after the another
推荐答案这取决于你将如何读取它。显而易见的选择是一系列提示,然后使用进行读取获取/与fgets 。将每个字符串读入一般工作缓冲区,以便在将值存储到结构中之前检查有效输入并进行任何必要的转换。 In您在上面显示的示例输入,您可以以相同的方式读取每一行(使用 gets / fgets )然后将其拆分为第一个空格字符以分隔变量名称来自实际数据。 It depends how you are going to read it in. The obvious choice would be a series of prompts followed by reads using gets/fgets. Read each string into a general work buffer so you can then check for valid input and do any conversions that may be necessary, before storing the values into your structure. In the sample input that you show above, you can just read each line the same way (using gets/fgets) and then split it at the first space character to separate the variable name from the actual data.
更多推荐
怎么采取多个字符串?
发布评论