Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what code you are actually running, because the <code>char filter = " "</code> line has no terminator and that assignment is definitely illegal. You cannot assign the string literal (a <code>char</code> array) to a single <code>char</code> variable.</p> <p>If you want to determine whether the nth character of a string is a tabulation, the following code would probably be what you are looking for:</p> <pre><code>if (line[counter] == '\t') { // match... } </code></pre> <hr> <p>As for updates. If typed as <code>string line = "1 90 74 84 48 76 76 80 85";</code> in your program, there are no tabulations in this string. There are only spaces. Moreover, <code>'\t\t'</code> is a pair of tables. Put a single <code>\t</code> in there for a single tab.</p> <p>Here is a slightly modified version of your sample function:</p> <pre><code>void getResults(string line) { int tmpSize = line.length(); int counter = 0; int tmpCounter = 0; while((tmpCounter &lt; tmpSize) &amp;&amp; (counter != MAX_No_Of_Grades)) { if(line[counter] == ' ') { counter++; } else { cout &lt;&lt; tmpCounter &lt;&lt; ". this is : " &lt;&lt; line[tmpCounter] &lt;&lt; "a" &lt;&lt; endl; tempGrade[counter] += line[tmpCounter]; } tmpCounter++; } } </code></pre> <p>This version has an extra check in the while loop to stop consuming characters after the end of <code>line</code> is reached. It also uses a space character since your test input does not use tabulations.</p> <hr> <p>If this is not homework and you can use all the standard library facilities you want, I would suggest looking into more advanced input strategies. Here is a simplified version of your function to extract every single number in the array.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;sstream&gt; void getResults ( const std::string&amp; line ) { std::istringstream input(line); for (int grade=0; input &gt;&gt; grade;) { // process grade. } } </code></pre> <p>If you want to remove the global variable and handle any number of grades, you can use a <code>std::vector&lt;&gt;</code> to automatically increase the "array" size as you get more and more grades.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;sstream&gt; #include &lt;vector&gt; std::vector&lt;int&gt; getResults ( const std::string&amp; line ) { std::istringstream input(line); std::vector&lt;int&gt; grades; for (int grade=0; input &gt;&gt; grade;) { grades.push_back(grade); } return grades; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload