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

  • SEARCH
  • Home
  • 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 8338999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:45:50+00:00 2026-06-09T04:45:50+00:00

i am new to C++. I would like to know how do i create

  • 0

i am new to C++. I would like to know how do i create a function to check for delimiter.

such as the case below

AD,Andorra,AN,AD,AND,20.00,Andorra la Vella,Europe,Euro,EUR,67627.00
AE,United Arab Emirates,AE,AE,ARE,784.00,Abu Dhabi,Middle East,UAE Dirham,AED,2407460.00
AF,Afghanistan,AF,AF,AFG,4.00,Kabul,Asia,Afghani,AFA,26813057.00

If the delimiter become $ or # instead of comma , how do i create a function to check for it and say , wrong format of text file.

Thanks!

Below is my readData code

void readData ()
{
    FILE * pFile;
    NoOfRecordsRead = 0;
    char buffer [Line_Char_Buffer_Size];

    pFile = fopen (INPUT_FILE_NAME , "r");

    if (pFile == NULL) 
        perror ("Error opening file 'Countries.txt' !");
    else
    {
        while ( !feof (pFile) )
        {
            char* aLine = get_line (buffer, Line_Char_Buffer_Size, pFile);

            if (aLine != NULL)
            {
//              printf ("%d] aLine => %s\n", NoOfRecordsRead, aLine);
                globalCountryDataArray [NoOfRecordsRead++] = createCountryRecord (aLine);
            }
        }

     fclose (pFile);

    }
}
  • 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-06-09T04:45:52+00:00Added an answer on June 9, 2026 at 4:45 am
    #include <string>
    #include <fstream>
    #include <algorithm>
    
    bool detect_comma(std::string file_name)
    {
        // open C++ stream to file
        std::ifstream file(file_name.c_str());
        // file not opened, return false
        if(!file.is_open()) return false;
        // read a line from the file       
        std::string wtf;
        std::istream &in= std::getline(file, wtf);
        // unable to read the line, return false
        if(!in) return false;
        // try to find a comma, return true if comma is found within the string
        return std::find(wtf.begin(), wtf.end(), ',')!= wtf.end();
    }
    
    
    #include <iostream>
    #include <cstdlib>
    
    int main()
    {
         if(!detect_comma("yourfile.dat"))
         {
             std::cerr<< "File is not comma delimited!\n";
             return EXIT_FAILURE;
         }
         // file is OK, open it and start reading
    }
    

    Edit: Added comments & example code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how do I add an error check to below
I'm new to win32api programming. I would like to know how to create a
Being new to OpenCL i would like to know if the following scenario is
Hi I'm new to SVN and would like to know a couple of things
I am new to using jquery and would like to know how to append
I'm new to jQuery and would like to know if it is possible to
we are starting a new project and I would like to know if V5
Hi i am new to android programming and i would like to know how
I am new here. I would like to know how can I display HTML
After initiating a new project, I would like to know when Petrel has completed

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.