Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:24+00:00 2026-05-27T10:09:24+00:00

I am trying to compare a string and a char like below : char

  • 0

I am trying to compare a string and a char like below :

char filter = "    " // <<== this is a tab space, so I am assuming its one char
if ( line[counter] == filter[0]){

}

note that line is a normal string defined like : string line;. now for some reason the statement is never true even though there are no syntax errors.

UPDATE

inside line is :
string line = "1 90 74 84 48 76 76 80 85";

2nd UPDATE

here is the complete function I wrote :

void getResults(string line){

    int tmpSize = line.length();
    int counter = 0;
    int tmpCounter = 0;

    while(counter != MAX_No_Of_Grades){

        if(line[counter] == '\t\t'){
            counter++;
        }else{
            cout << tmpCounter << ". this is : " << line[tmpCounter] << "a" << endl;
            tempGrade[counter] += line[tmpCounter];
        }
        tmpCounter++;
    }


}

the function is technically suppose to break the string line into an array by “tabspace”. but right now counter does not change and therefore its an endless loop!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:09:24+00:00Added an answer on May 27, 2026 at 10:09 am

    I’m not sure what code you are actually running, because the char filter = " " line has no terminator and that assignment is definitely illegal. You cannot assign the string literal (a char array) to a single char variable.

    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:

    if (line[counter] == '\t') {
      // match...
    }
    

    As for updates. If typed as string line = "1 90 74 84 48 76 76 80 85"; in your program, there are no tabulations in this string. There are only spaces. Moreover, '\t\t' is a pair of tables. Put a single \t in there for a single tab.

    Here is a slightly modified version of your sample function:

    void getResults(string line)
    {
        int tmpSize = line.length();
        int counter = 0;
        int tmpCounter = 0;
        while((tmpCounter < tmpSize) && (counter != MAX_No_Of_Grades))
        {
            if(line[counter] == ' ') {
                counter++;
            }
            else {
                cout << tmpCounter << ". this is : " << line[tmpCounter] << "a" << endl;
                tempGrade[counter] += line[tmpCounter];
            }
            tmpCounter++;
        }
    }
    

    This version has an extra check in the while loop to stop consuming characters after the end of line is reached. It also uses a space character since your test input does not use tabulations.


    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.

    #include <iostream>
    #include <string>
    #include <sstream>
    void getResults ( const std::string& line )
    {
        std::istringstream input(line);
        for (int grade=0; input >> grade;) {
            // process grade.
        }
    }
    

    If you want to remove the global variable and handle any number of grades, you can use a std::vector<> to automatically increase the “array” size as you get more and more grades.

    #include <iostream>
    #include <string>
    #include <sstream>
    #include <vector>
    std::vector<int> getResults ( const std::string& line )
    {
        std::istringstream input(line);
        std::vector<int> grades;
        for (int grade=0; input >> grade;) {
            grades.push_back(grade);
        }
        return grades;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compare a character array against a string like so: const char
suppose there is a string like this string temp2 = hello; char[] m =
I'm trying to compare a character string with the argv argument. I have this
I am trying to compare two text files and output the first string in
I'm trying to compare two strings. One stored in a file, the other retrieved
I am trying to compare std::string s in a locale-dependent manner. For ordinary C-style
compiling with gcc C99 I am trying to compare 2 string using string compare.
I'm basicly trying to compare a token(string) with a hex-datatype! Example: #include<stdio.h> #include<string.h> int
I'm trying to exploit my format string bug, which lies in this program: #include
So I'm trying to make a brute force string generator to match and compare

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.