logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings Comments

  • Question
  • Which of the following function is more appropriate for reading in a multi-word string?


  • Options
  • A. printf();
  • B. scanf();
  • C. gets();
  • D. puts();

  • Correct Answer
  • gets(); 

    Explanation
    gets(); collects a string of characters terminated by a new line from the standard input stream stdin

    #include <stdio.h>
    
    int main(void)
    {
       char string[80];
    
       printf("Enter a string:");
       gets(string);
       printf("The string input was: %s\n", string);
       return 0;
    }
    

    Output:

    Enter a string: CuriousTab

    The string input was: CuriousTab


    Strings problems


    Search Results


    • 1. Which of the following function is correct that finds the length of a string?

    • Options
    • A.
      int xstrlen(char *s)
      {
          int length=0;
          while(*s!='\0')
          {    length++; s++; }
          return (length);
      }
      
    • B.
      int xstrlen(char s)
      {
          int length=0;
          while(*s!='\0')
              length++; s++;
          return (length);
      }
      
    • C.
      int xstrlen(char *s)
      {
          int length=0;
          while(*s!='\0')
              length++;
          return (length);
      }
      
    • D.
      int xstrlen(char *s)
      {
          int length=0;
          while(*s!='\0')
              s++;
          return (length);
      }
      
    • Discuss
    • 2. If the two strings are identical, then strcmp() function returns

    • Options
    • A. -1
    • B. 1
    • C. 0
    • D. Yes
    • Discuss
    • 3. Which of the following function sets first n characters of a string to a given character?

    • Options
    • A. strinit()
    • B. strnset()
    • C. strset()
    • D. strcset()
    • Discuss
    • 4. The library function used to find the last occurrence of a character in a string is

    • Options
    • A. strnstr()
    • B. laststr()
    • C. strrchr()
    • D. strstr()
    • Discuss
    • 5. How will you print \n on the screen?

    • Options
    • A. printf("\n");
    • B. echo "\\n";
    • C. printf('\n');
    • D. printf("\\n");
    • Discuss
    • 6. To scan a and b given below, which of the following scanf() statement will you use?
      #include<stdio.h>
      
      float a;
      double b;
      

    • Options
    • A. scanf("%f %f", &a, &b);
    • B. scanf("%Lf %Lf", &a, &b);
    • C. scanf("%f %Lf", &a, &b);
    • D. scanf("%f %lf", &a, &b);
    • Discuss
    • 7. Out of fgets() and gets() which function is safe to use?

    • Options
    • A. gets()
    • B. fgets()
    • Discuss
    • 8. To print out a and b given below, which of the following printf() statement will you use?
      #include<stdio.h>
      
      float a=3.14;
      double b=3.14;
      

    • Options
    • A. printf("%f %lf", a, b);
    • B. printf("%Lf %f", a, b);
    • C. printf("%Lf %Lf", a, b);
    • D. printf("%f %Lf", a, b);
    • Discuss
    • 9. In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?

    • Options
    • A. "I am a boy\r\n\0"
    • B. "I am a boy\r\0"
    • C. "I am a boy\n\0"
    • D. "I am a boy"
    • Discuss
    • 10. Which files will get closed through the fclose() in the following program?
      #include<stdio.h>
      
      int main()
      {
          FILE *fs, *ft, *fp;
          fp = fopen("A.C", "r");
          fs = fopen("B.C", "r");
          ft = fopen("C.C", "r");
          fclose(fp, fs, ft);
          return 0;
      }
      

    • Options
    • A. "A.C" "B.C" "C.C"
    • B. "B.C" "C.C"
    • C. "A.C"
    • D. Error in fclose()
    • Discuss


    Comments

    There are no comments.

Enter a new Comment