gets

c - how gets() work after scanf? [duplicate]

六眼飞鱼酱① 提交于 2021-02-04 05:13:39
问题 This question already has answers here : scanf() leaves the new line char in the buffer (4 answers) Closed 3 years ago . I have two questions: why only when i do space in "%d " --> scanf("%d ", &num); it works? I tried fflush(stdin) \ _flushall() between the scnaf and the gets and it doesn't works, it skips the gets. When I do the space, it first does scanf then the gets and after that it print the number and print the string. void main() { char ch, str[10]; int num; printf("Enter your number

c - how gets() work after scanf? [duplicate]

南笙酒味 提交于 2021-02-04 05:11:03
问题 This question already has answers here : scanf() leaves the new line char in the buffer (4 answers) Closed 3 years ago . I have two questions: why only when i do space in "%d " --> scanf("%d ", &num); it works? I tried fflush(stdin) \ _flushall() between the scnaf and the gets and it doesn't works, it skips the gets. When I do the space, it first does scanf then the gets and after that it print the number and print the string. void main() { char ch, str[10]; int num; printf("Enter your number

c - how gets() work after scanf? [duplicate]

爱⌒轻易说出口 提交于 2021-02-04 05:10:39
问题 This question already has answers here : scanf() leaves the new line char in the buffer (4 answers) Closed 3 years ago . I have two questions: why only when i do space in "%d " --> scanf("%d ", &num); it works? I tried fflush(stdin) \ _flushall() between the scnaf and the gets and it doesn't works, it skips the gets. When I do the space, it first does scanf then the gets and after that it print the number and print the string. void main() { char ch, str[10]; int num; printf("Enter your number

Exploit Development - GETS and Shellcode

给你一囗甜甜゛ 提交于 2020-12-05 11:49:06
问题 Trying to learn more about exploit dev and building shellcodes, but ran into an issue I don't understand the reason behind. Why am I not able to run a shellcode such as execve("/bin/sh") and spawn a shell I can interact with? While on the other hand, I'm able to create a reverse / bind_tcp shell and connect to it with netcat. Sample program: // gcc vuln.c -o vuln -m32 -fno-stack-protector -z execstack #include <stdio.h> #include <string.h> void test() { char pass[50]; printf("Password: ");

Gets(string#) function skipping first gets request

六眼飞鱼酱① 提交于 2020-04-28 20:26:07
问题 I'm working on a project for my own personal leisure and learning. Part of it looks like this: #include<stdio.h> #include<string.h> wgame() { char string3[12], string2[12], string1[12], string4[12], string5[12]; memset (string1, 0, 11); memset (string2, 0, 11); memset (string3, 0, 11); memset (string4, 0, 11); memset (string5, 0, 11); printf("reference C correct\n"); printf("Okay, so you want a game. Here's one for you\n\n\n"); printf("This is a word game.\n\n A noun is a person place or

Can I use a pointer as the parameter of gets in C?

我的梦境 提交于 2020-03-16 08:07:28
问题 I am studying the C language. When I pass a pointer to gets(), I find it can work well. char *ptr; gets(ptr); puts(ptr); But if I define an array of pointers, it doesn't work. char *ptr[4]; int i=0; for(i=0;i<4;++i) gets(ptr[i]); for(i=0;i<4;++i) puts(ptr[i]); Are they different, or is the first part wrong in fact? I want to know the reason. 回答1: You pass a pointer to a function (e.g. gets() ) that writes data to a memory location pointed by your pointer. In your case, you have the

Prevent buffer overflows with gets [duplicate]

ε祈祈猫儿з 提交于 2020-01-09 11:39:10
问题 This question already has answers here : Why is the gets function so dangerous that it should not be used? (11 answers) Closed 2 years ago . The declaration of gets is: char * gets ( char * str ); Note the glaring omission of a maximum size for str . cplusplus.com says 2 : Notice that gets is quite different from fgets: not only gets uses stdin as source, but it does not include the ending newline character in the resulting string and does not allow to specify a maximum size for str ( which