Question

In: Computer Science

When you read data in (without using getLine) how is the data read. does it read...

When you read data in (without using getLine) how is the data read. does it read spaces and line breakers(\n). Also how can you read a paragraph into a double vector of strings ( into words and strings again without using getLine)

Solutions

Expert Solution

When a data is read using getLine, it is generally read over the entire string input separated by space (' '). The input is terminated by a newline character ('\n').

For example - let us assume our input is - "A brown fox is hungry."

Then it can be stored in a array of string as {"A", "brown", "fox", "is", "hungry"}.

Separated by space and terminated by a newline character.

Code to illustrate


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMSTR 3
#define BUFFSIZE 100

int main()
{    
  char *words[NUMSTR];
  char buffer[BUFFSIZE];
  int i, count = 0, slen;

  /* loops only for three input strings */
  for (i = 0; i < NUMSTR; i++)
  {
    printf("Enter a word: ");
    scanf("%s", buffer);
    words[count] = (char *) malloc(strlen(buffer) + 1);
    strcpy(words[count], buffer);
    count++;
  }

  /* reading input is finished, now time to print and free the strings */
  printf("\nYour strings:\n");
  for (i = 0; i < NUMSTR; i++)
  {
    printf("words[%u] = %s\n", i, words[i]);
  }

  return 0;
}


Related Solutions

Using this data on how to calculate the approximate formula, without the bond prices
India1Y5.69%2Y5.78%5Y6.29%10Y6.60%20Y7.03%30Y7.06%Using this data on how to calculate the approximate formula, without the bond prices, we can calculate future discount rates / forward rates in excel(1+ DR1) (1+ DR2) = (1+YTM2)2
Exercise 3 Step 1: When you read Storing Data Using Sets, you learned that Python's set...
Exercise 3 Step 1: When you read Storing Data Using Sets, you learned that Python's set type allows us to create mutable collections of unordered distinct items. The items stored in a set must be immutable, so sets can contain values of type int, float or str, but we can't store lists or sets in sets. Tuples are immutable, so we can store tuples in sets. Try this experiment, which creates a set containing the points (1.0, 2.0), (4.0, 6.0)...
Using the below question and values how do you calculate the standard deviation without using a...
Using the below question and values how do you calculate the standard deviation without using a calculator (by hand) of (s1^2/n1+s2^2/n2) with the standard deviation answer being 1.4938 and 1.1361 /sqrt(1.4938^2/10 + 1.1361^2/10) Choose two competing store and compare the prices of 10 items at both stores. Preform a two-sample hypothesis test to try an prove if one store is more expensive than the other based on your sample. Store A item #1-$5.49, #2 $3.77, #3 $0.87, #4 $3.29, #5...
How can this problem be done WITHOUT using R? For the bird egg length data set,...
How can this problem be done WITHOUT using R? For the bird egg length data set, conduct an appropriate test to determine if bird egg length differs among species. Assume that before you conducted this test you hypothesized about 3 contrasts a priori. These were that (1) Meadow Pipits, Wagtails, and Robins would be different than the other 3 bird species, (2) Hedge Sparrows would differ from Wrens, and (3) Tree Pipits would be different than all other birds. Use...
What is Mirr? how do you find it using excel without using excel formula? Below is...
What is Mirr? how do you find it using excel without using excel formula? Below is cash flow. I found IRR is 15.59% and required return is 12% CF Y0 Y1 Y2 Y3 Y4 Y5 Y6 Capital spen $ (30,000,000.00) $ 15,062,400.00 Opp cost $   (5,000,000.00) NWC $   (1,120,000.00) $      (150,000.00) $      (170,000.00) $      140,000.00 $   1,300,000.00 OCF $     9,015,600.00 $ 11,392,500.00 $ 12,193,200.00 $ 10,435,800.00 $ (2,640,000.00) $   (3,960,000.00) CF $ (36,120,000.00) $     8,865,600.00 $ 11,222,500.00 $ 12,333,200.00 $...
Explain using examples, ‘how’ and ‘why’ you would collect Sensitivity and Specificity data when performing a...
Explain using examples, ‘how’ and ‘why’ you would collect Sensitivity and Specificity data when performing a Validation Study on a new DNA STR Profiling Kit.
Using IT for Decision Making First, read Week 2 Content on Data and How Information Supports...
Using IT for Decision Making First, read Week 2 Content on Data and How Information Supports Decision Making, paying particular attention to the Levels of Decision Making. For purposes of this discussion, we will use a retail business as an example. This retail business is comprised of the corporate headquarters, regions (oversees several stores in a geographic area) and individual stores. Each of these aligns to one of the three levels of decision makers in an organization.   Main Postings: Select...
Without using a Timer function, write a program to read the distance from the HC-SR04 ultrasonic...
Without using a Timer function, write a program to read the distance from the HC-SR04 ultrasonic sensor and display the distance on the C12832 lcd. *please refer the HC-SR04 datasheet for the operation of the ultrasonic sensor, and mbed website for C12832 library and Timer function
Without using formulas, explain how you can determine each of the following: c. If you have...
Without using formulas, explain how you can determine each of the following: c. If you have 10 people, how many different committees of 3 people can be formed for the offices of president, vice-president, and secretary? d. Does order matter or not for part c? Explain.
In a Servlet, how do you read HTML Form Data (data from the previous Web page)...
In a Servlet, how do you read HTML Form Data (data from the previous Web page) into the Servlet?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT