简体   繁体   English

如何在C中以整数类型数组作为输入的前缀? 当我使用%[^ \\ n]输入字符串时

[英]How can i prefixed to take input in an integer type array in c? When i use %[^\n] in case of string input

Hey i am a new bee in c programming.... I have faced the following problem... 嘿,我是C语言编程中的新蜂。...我遇到了以下问题...

#include<stdio.h>
main(){
  char line[80];
  scanf("%[^\n]",line); /*here i say it is terminated when new line encounterd*/
  printf("%s",line);
}

This code work for taking string input in a line and also force scanf to take input with space... 该代码用于在一行中接受字符串输入,并强制scanf以空格进行输入...

#include<stdio.h>
main(){
    char line[80];
    scanf(" %[ ABCD]",line); /*here i say when program encountered anything without blankspace, A,B,C,D it is terminated*/
    printf("%s",line);
}

here an another code which take only blank space and 'A','B','C','D' 这是另一个仅占用空格和'A','B','C','D'的代码

if i want to do this job in case of integer type by using this what can i do? 如果我想通过使用此功能在整数类型的情况下完成这项工作,该怎么办?

try this: 尝试这个:

#include <stdio.h>

int main (void) {
   int i;
   printf("Please enter a number: ");
   scanf("%d",&i);      /* Waits for input.    */
   printf("You entered %d\n",i);
   return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能在c中输入多个字符串? - How can i take multiple string input in c? 要在字符后输入整数,我使用了“ %c ”,但在没有给出整数作为输入时不运行 - To take an integer input after character I used " %c " but does not run when no integer given as input 我如何声明一个 int 类型的输入变量,例如。 输入 x(0 - How can i declare a int type input variable eg. take a input x(0<x<1000) in c? 如何强制scanf将\\ n字符作为输入? - how can I force scanf to take the \n character as input? 我可以在scanf中使用指针来获取数组中的输入吗? - Can i use pointer in scanf to take input in an array? 如何初始化n维的多维数组,其中n是C中用户的输入? - How can I initialize a multidimensional array of n dimensions where n is the input from a user in C? 我可以使用什么来代替 C 中的 scanf 输入 integer? - What can I use for taking integer input instead of scanf in C? 我如何将十六进制输入从用户C接受到数组 - How i take hex input into array from users c 如何在单行输入中获取整数数组[在C中] - How to take a integer array in a single line input [in C] 如何使用 %c 获取字符数组中的输入字符并使用 %s 生成正确的 output? - How can I take input character in a character array using %c and produce the right output using %s?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM