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 7554013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:13:17+00:00 2026-05-30T11:13:17+00:00

can you help me with this.. what i’m trying to accomplish is that when

  • 0

can you help me with this.. what i’m trying to accomplish is that when the user inputs his/her username and password, my program will then open a file which is the storage of the users information arranged by line (username,password,foldername,user’s full name). I have this code but i can’t seem to see the problem. When the input should have the result of the first line, it gets it. But when it parses the second line, it crashes. Can someone help me with this?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

main () {
//  string toks[]; 
  char oneline[80],*del;
  string line, creds[3], username, password;
  int x = 0;
  cout<<"Enter Username: ";
  cin>>username;
  cout<<"Enter Password: ";
  cin>>password;
  ifstream myfile;
   myfile.open("jake.txt");
  if (myfile.is_open())
  {

    while (!myfile.eof())
    {
     getline(myfile,line);
     strcpy(oneline,line.c_str());
     del = strtok(oneline,",");
     while(del!=NULL)
     {
     creds[x] = del;
     del = strtok(NULL,",");
     ++x;
     }
     if((creds[0]==username)&&(creds[1]==password))
        {
         cout<<creds[2]<<endl;
         break;
         }
    }
    myfile.close();
  }
  else 
  cout << "Unable to open file"; 

  system("pause");
}
  • 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-30T11:13:18+00:00Added an answer on May 30, 2026 at 11:13 am

    probably you are overflowing the oneline buffer.
    Instead of using a fixed size, just use std::string, as you are doing for other vars.
    i.e.

    string oneline;
    ...
    oneline = line;
    ...
    

    and use boost tokenizer for split on comma, instead of strtok

    edit:sample usage, adapted from boost docs

    #include<iostream>
    #include<boost/tokenizer.hpp>
    #include<string>
    
    int tokenizer_main(int, char **){
       using namespace std;
       using namespace boost;
       string s = "This,is,a,test";
       tokenizer<> tok(s);
       for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
           cout << *beg << "\n";
       }
    }
    

    outputs

    This
    is
    a
    test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone can help with this please. I am trying to query an
I hope someone can help with this. I have created a map app that
Hoping someone can help with this. I have other VM's that dont have problems,
I'm hoping there will be a CSS guru out there that can help with
I hope that there is someone that can help with this problem since I
Hope that someone out there can help with this! I'll give an example based
I'm hoping someone can help with this question. I'm also hoping that this question
Not sure if there's a php function that can help determine this. I have
Hope someone can help with this: Am trying to delete session files on /tmp
Not sure if yall can help this time, as I'm just using this particular

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.