我是链接列表的新手,现在我在节点数量方面遇到的问题很少.
在这里,我可以填充链表的第一个节点,但该gets()函数似乎没有暂停执行以填充下一个节点.
输出如下:
Var name : var
Do you want to continue ?y
Var name : Do you want to continue ? // Here I cannot input second data
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
struct data
{
char name[50];
struct data* next;
};
struct data* head=NULL;
struct data* current=NULL;
void CreateConfig()
{
head = malloc(sizeof(struct data));
head->next=NULL;
current = head;
char ch;
while(1)
{
printf("Var name : ");
gets(current->name); //Here is the problem,
printf("Do you want to continue ?");
ch=getchar();
if(ch=='n')
{ …Run Code Online (Sandbox Code Playgroud) 我是Buffer Overflow漏洞的新手,我从一个简单的C程序开始.
码
#include <stdio.h>
#include <strings.h>
void execs(void){
printf("yay!!");
}
void return_input (void)
{
char array[30];
gets(array);
}
int main()
{
return_input();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译阶段
我通过禁用stack protectoras来编译上面的cc程序:
cc test.c -o test -fno-stack-protector
Run Code Online (Sandbox Code Playgroud)
使用elf文件的转储objdump如下:
0804843b <execs>:
804843b: 55 push %ebp
804843c: 89 e5 mov %esp,%ebp
804843e: 83 ec 08 sub $0x8,%esp
8048441: 83 ec 0c sub $0xc,%esp
8048444: 68 10 85 04 08 push $0x8048510
8048449: e8 b2 fe ff ff call 8048300 <printf@plt>
804844e: …Run Code Online (Sandbox Code Playgroud) 我的 Ruby 脚本类似于:
something = gets # or STDIN.gets
puts something
def arrow_pressed
puts "arrow totally pressed"
end
Run Code Online (Sandbox Code Playgroud)
一旦用户提示存在,我希望除箭头键之外的所有键盘输入正常发生。如果按下这些按钮,我不希望终端中出现任何内容(例如^[[A)。我只想执行我的arrow_pressed方法。我想执行它而不需要用户点击Return
我已经尝试过这个要点- 效果很好,只是即使在更改它以正常地通过大多数击键之后,我仍然无法Backspace(或其他特殊功能)工作。
我很高兴使用gets(图书馆或其他什么)以外的东西。任何帮助,将不胜感激!
我有一个与char指针的动态内存分配有关的奇怪问题.我有类似的东西
char *input = new char; //1
gets(input) //2
char *dest = new char; //3Run Code Online (Sandbox Code Playgroud)
在step3期间,我在运行时遇到堆损坏错误.仅当我输入的字符串长度超过23个字符时才会发生这种情况.
如果我不做任何新的操作,那么没有问题.
如果我指定,此问题已解决
char *input = new char[100];
但我希望输入是基于用户输入的动态.
我不确定在这种情况下24字节的作用是什么.我不想限制为100或者n个字符...我在内存分配方面有点弱......有人可以解释这种情况吗?
我是 C 新手,正在做一些练习,但在 while 循环中使用 get() 时遇到问题。在搜索中,我相信它可能与 \n 字符有关,但我希望有人能够更彻底地解释这里发生的事情:
这个循环只会运行一次——它会第二次打印“输入姓氏”以进行筛选,然后在 get() 有机会再次接受任何输入之前退出循环:
while (employee_num <= 10)
{
printf("Enter last name ");
gets(employee[employee_num].last_name);
if(strlen(employee[employee_num].last_name) == 0)
break;
printf("Enter first name ");
gets(employee[employee_num].first_name);
printf("Enter title ");
gets(employee[employee_num].title);
printf("Enter salary ");
scanf("%d", &employee[employee_num].salary);
++employee_num;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我了解了\n,在结束时会自动的puts和gets,以及如何处理这些,但有没有办法让显示器点("光标位置",如果你愿意)移动到一个新行击中后输入输入gets?
例如
print 'Hello, my name is '
a = gets.chomp
print ', what's your name?'
Run Code Online (Sandbox Code Playgroud)
最终看起来像
你好,我叫Jeremiah,你叫什么名字?
我是C编程新手(尽管我有Java经验)。阅读了一些教程之后,我决定开始解决Coderbyte上的编码难题。
我尝试的第一个挑战是这一个:
挑战
让函数FirstFactorial(num)接受传递的num参数并返回其阶乘。例如:如果num = 4,则您的程序应返回(4 * 3 * 2 * 1) =24。对于测试用例,范围将在1到18之间,并且输入将始终是整数。
样本测试用例
输入:4
输出:24输入:8
输出:40320
我的解决方案:
#include <stdio.h>
void FirstFactorial(int num[]) {
int i = num -1;
for(i ; i > 0; i--) {
num = num * i;
printf("%d",i);
}
printf("\t %d", num);
}
int main(void) {
// disable stdout buffering
setvbuf(stdout, NULL, _IONBF, 0);
// keep this function call here
FirstFactorial(gets(stdin));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入参数的值: …
我正在运行一个 CTF,目前正在编写一个利用 Cgets函数的问题。我知道该函数已被弃用且危险,我绝不会在任何其他情况下使用它。不幸的是,gcc编译我的代码,当我在函数被调用时运行二进制文件时gets,我收到一条友好的错误消息:
warning: this program uses gets(), which is unsafe.
Run Code Online (Sandbox Code Playgroud)
这通常会很好,因为它会警告您 gets 是不安全的,但不幸的是,在我的 CTF 中,我认为这个错误消息使问题变得有点太简单了。你知道我将如何禁用此警告吗?谢谢!
warning: this program uses gets(), which is unsafe.
Run Code Online (Sandbox Code Playgroud) 我有一个用C编写的程序,当用户选择3的选项时,它从一个开关调用gets().这是我的代码.它似乎还没等到等待用户输入内容.相反,程序在交换机中继续.
void getField();
#include <stdio.h>
#include <string.h>
/*#include "stubs.c"
#include "record.h" */
int debugMode;
void getField(){
char name[25];
char address[80];
int yearofbirth;
char telno[15];
int counter = 0;
if(debugMode == 1){
printf("***DEBUG*** Entering getField function \n");
}
printf("Enter your name:");
gets(name);
printf("Name: %s \n", name);
printf("\n");
}
void main(int argc, char * argv[])
{
struct record* start = NULL;
int userChoice;
debugMode = 0;
if(argv[1] != NULL){
if( (strcmp(argv[1], "debug") == 0) && (argv[2] == NULL) ){
debugMode = 1; …Run Code Online (Sandbox Code Playgroud) 我正在制作一个程序来接受教师结构中的输入,但存在未知的运行时错误,这是代码 -
#include <stdio.h>
#include <conio.h>
struct Teacher
{
char Name[30];
char Qualifications[20];
int experience_year;
}th[10];
void teacher()
{
int t,i;
printf("Enter how many teachers are in department\n");
scanf("%d",&t);
for(i=1;i<=t;i++)
{
printf("Enter name of teacher : ");
gets(th[i].Name);
printf("Enter qualification of teacher : ");
gets(th[i].Qualifications);
printf("Enter experience_year of teacher : ");
scanf("%d",&th[i].experience_year);
}
for(i=1;i<=t;i++)
{
printf("Details of %d teacher\n",i);
printf(th[i].Name);
printf(" ");
printf(th[i].Qualifications);
printf(" ");
printf("%d",th[i].experience_year);
printf("\n");
}
}
int main()
{
teacher();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是 -
Enter number …Run Code Online (Sandbox Code Playgroud)