gets

How can I store user defined data in a hash

巧了我就是萌 提交于 2019-12-08 11:48:06
问题 Help, I am a noob, just need some advice on this bit of code. I have got most of my program working this part has me stuped i want to get a name and password. Then make the name the key and the password the value. Now it must be user defined.. Then I must be able to pull that hash info again. I thought that return would work... here is my code def login_prompt vault = {} puts "WELCOME! please enter an existing username: " username = gets.chomp checkname = Noxread.new comparename = checkname

C structure not scanning all the inputs

ぐ巨炮叔叔 提交于 2019-12-06 11:11:29
I have this C code: #include "stdio.h" main() { struct books { char name[100],author[100]; int year,copies; }book1,book2; printf("Enter details of first book\n"); gets(book1.name); gets(book1.author); scanf("%d%d",&book1.year,&book1.copies); printf("Enter details for second book\n"); gets(book2.name); gets(book2.author); scanf("%d%d",&book2.year,&book2.copies); printf("%s\n%s\n%d\n%d\n",book1.name,book1.author,book1.year,book1.copies); printf("%s\n%s\n%d\n%d\n",book2.name,book2.author,book2.year,book2.copies); } What is happening here is that it only scans till the author name of the second

c : gets() and fputs() are dangerous functions?

烂漫一生 提交于 2019-12-04 21:26:12
In the computer lab at school we wrote a program using fputs and the compiler returned an error gets is a dangerous function to use and a similar error for fputs but at home when i type in this bit of code: #include <stdio.h> main() { FILE *fp; char name[20]; fp = fopen("name.txt","w"); gets(name); fputs(name,fp); fclose(fp); } i get no errors what so ever. The one at school was similar to this one, just a bit lengthy and having more variables. I use codeblocks at home and the default gcc provided with fedora at school. Could it be a problem with the compiler? With gets you need exactly know

Why can I use gets() in gcc -std=c11?

送分小仙女□ 提交于 2019-12-04 17:17:38
问题 The gets() function has been removed from the C language. No such function exists in the standard. Yet I compile the following code: #include <stdio.h> int main (void) { (void) gets (NULL); } using gcc -std=c11 -pedantic-errors -Wall -Wextra and it compiles without giving any errors or warnings. Similarly, #include <stdio.h> int gets; int main (void) {} will not compile (error: 'gets' redeclared as different kind of symbol). In the standard 4. Conformance §6 we can read: A conforming

gets() function and '\0' zero byte in input

被刻印的时光 ゝ 提交于 2019-12-04 02:17:43
问题 Will the gets() function from C language (e.g. from glibc) stop, if it reads a zero byte ( '\0' ) from the file ? Quick test: echo -ne 'AB\0CDE' Thanks. PS this question arises from comments in this question: return to libc - problem PPS the gets function is dangerous, but it is a question about this function itself, not about should anybody use it or not. 回答1: The behavior of gets() is that it stops when a newline character is encountered or if EOF is encountered. It does not care if it

Why can I use gets() in gcc -std=c11?

妖精的绣舞 提交于 2019-12-03 12:24:52
The gets() function has been removed from the C language. No such function exists in the standard. Yet I compile the following code: #include <stdio.h> int main (void) { (void) gets (NULL); } using gcc -std=c11 -pedantic-errors -Wall -Wextra and it compiles without giving any errors or warnings. Similarly, #include <stdio.h> int gets; int main (void) {} will not compile (error: 'gets' redeclared as different kind of symbol). In the standard 4. Conformance §6 we can read: A conforming implementation may have extensions (including additional library functions), provided they do not alter the

Why and how gcc emits warning for gets()?

这一生的挚爱 提交于 2019-12-03 01:18:01
问题 while(1) { printf("\nEnter message : "); gets(message); //Send some data if( send(sock , message , strlen(message) , 0) < 0) { puts("Send failed"); return 1; } //Receive a reply from the server if( recv(sock , server_reply , 2000 , 0) < 0) { puts("recv failed"); break; } puts("Server reply :"); puts(server_reply); } close(sock); return 0; } This is part of my program. When I compile and run it, I get an error. The error's message is warning: the gets function is dangerous and should not be

Is it possible using gets without knowing the length of the array in c?

天大地大妈咪最大 提交于 2019-12-02 23:17:34
问题 If we want to use gets in c we will do something like: int main(void) { char str[100]; while (gets(str)) { printf("%s\n",str); } } We have to know the length of str first(which is 100) and then use gets. Is it possible using gets without knowing the length of the array in c? 回答1: If you mean using gets safely, no, it's not possible. Advice : don't use gets , because without knowing the length first, it may cause buffer overflow. Use fgets instead, or use gets_s in C11. In fact, gets has been

C: gets() skips the first input [closed]

不问归期 提交于 2019-12-02 21:36:57
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct record { char name[20]; char surname[20]; char telephone[20]; }Record; typedef struct node { Record data; struct node *next; }Node; Node *head = NULL; void addRecord(Record s) { Node *newNode; Node *n; newNode = (Node*

Strings, gets and do while

谁说胖子不能爱 提交于 2019-12-02 15:54:31
问题 I'm doing an exercise in C but I have a problem when at the and I want to repeat the cicle (do while), infact if I type 1 the programme starts again by the top, but it doesn't stop at the gets(testo); . I tried plenty of ways to solve the bug without a solution, can anyone help me? #include <stdlib.h> #include <stdio.h> #include <string.h> main(){ int cch, cw, i, j, w, ord, f; //counter and index char testo[80]; char alfa[50][25]; char swap[25]; do{ cch=0; cw=0; j=0; w=0; f=0; for(i=0;i<80;i+