Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sir? Builtin Function Help

Sir? Builtin Function Help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NaumanMalik
    wrote on last edited by
    #1

    Hi, How are you?...i hope you are doing fine... i want to ask is there any built in function to get on exact line in a file? Like: FILE DATA: 1)Start 2)Mid 3)Username 4)END i want to get the pointer of file handler on 3 so that i can read that specific line.... or Can we use Seekg.(); function in this case? Kindly help please

    Greg UtasG L 3 Replies Last reply
    0
    • N NaumanMalik

      Hi, How are you?...i hope you are doing fine... i want to ask is there any built in function to get on exact line in a file? Like: FILE DATA: 1)Start 2)Mid 3)Username 4)END i want to get the pointer of file handler on 3 so that i can read that specific line.... or Can we use Seekg.(); function in this case? Kindly help please

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      I don't know of such a function. If each line ends in an '\n', you can use std::getline to read each one and count up to the line you want. seekg moves by a specified number of characters, so it won't help unless lines are padded to a fixed length.

      Robust Services Core | Software Techniques for Lemmings | Articles

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      N 1 Reply Last reply
      0
      • Greg UtasG Greg Utas

        I don't know of such a function. If each line ends in an '\n', you can use std::getline to read each one and count up to the line you want. seekg moves by a specified number of characters, so it won't help unless lines are padded to a fixed length.

        Robust Services Core | Software Techniques for Lemmings | Articles

        N Offline
        N Offline
        NaumanMalik
        wrote on last edited by
        #3

        #include
        #include
        using namespace std;

        void Signup(int UserCheck)
        {
        char Firstname[30] = { 0 }, Lastname[30] = { 0 }, Username[11] = { 0 }, Password[11] = { 0 }, ConfirmPassword[11] = { 0 }, File[50] = { 0 }, CNIC[16] = { 0 };
        cout << "Sign Up:\nFirst Name: "; cin >> Firstname;
        cout << "Last Name: "; cin >> Lastname;
        ifstream Read;
        while(true)
        {
        cout << "Uername (eight to ten letters only): "; cin >> Username;
        if(UserCheck == 1)
        {
        strcat(File, "S"); strcat(File, Username); strcat(File, ".txt");
        }
        else if(UserCheck == 2)
        {
        strcat(File, "B"); strcat(File, Username); strcat(File, ".txt");
        }
        Read.open(File);
        if((strlen(Username) >= 8 && strlen(Username) <= 10) && (!(Read.is_open())))
        {
        Read.close();
        break;
        }
        else
        {
        cout << "\nUsername should be unique and contain 8-10 letters only.\n";
        }
        }
        cout << "CNIC:";
        for(int i = 0; i < 15; i++)
        {
        if(i == 5 || i == 13)
        {
        cout << "-"; CNIC[i] = '-';
        }
        else
        {
        cin >> CNIC[i];
        }

        }
        while(true)
        {
        	cout << "Password: "; cin >> Password;
        	if(strlen(Password) >= 8 && strlen(Password) <= 10)
        	{
        		while(true)
        		{
        			cout << "Confirm Password: "; cin >> ConfirmPassword;
        			if(strcmp(Password, ConfirmPassword) == 0)
        			{
        				break;
        			}
        			else
        			{
        				cout << "\\nPassword did not matched.\\n";
        			}
        		}
        		break;
        	}
        	else
        	{
        		cout << "\\nPassword is not acceptable, it should have only 8-10 letters.\\n";
        	}
        }
        ofstream Write(File);
        Write << Firstname << endl;
        Write << Lastname << endl;
        Write << Username << endl;
        Write << CNIC << endl;
        Write << Password << endl;
        Write.close();
        

        }
        //void Login(int UserCheck)
        //{
        // char File[50] = { 0 }, Username[11] = { 0 }, Password[11] = { 0 }, CheckPassword[11] = { 0 };
        // ifstream Read;
        // while(true)
        // {
        // cout << "Uername (eight to ten letters only): "; cin >> Username;
        // if(UserCheck == 1)
        // {
        // strcat(File, "S"); strcat(File, Username); strcat(File, ".txt");
        // }
        // else if(UserCheck == 2)
        // {
        // strcat(File, "B"); strcat(File, Username); strcat(File, ".txt");
        // }
        // Read.open(File);
        // if((strlen(Username) >= 8 && strlen(Username) <= 10) && (Read.is_open()))
        // {
        // break;
        // }
        // else
        // {
        // cout << "\nInvalid Username.\n";
        // }
        // }
        // int Line = 1, i = 0; char temp = 0;
        // while(Line != 5);
        // {
        // Read>>temp;
        // cout << temp;
        // if(temp == '\n')
        // {
        // Line++;
        // }
        // i++;
        // }

        1 Reply Last reply
        0
        • N NaumanMalik

          Hi, How are you?...i hope you are doing fine... i want to ask is there any built in function to get on exact line in a file? Like: FILE DATA: 1)Start 2)Mid 3)Username 4)END i want to get the pointer of file handler on 3 so that i can read that specific line.... or Can we use Seekg.(); function in this case? Kindly help please

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          The simplest way to do this is to read the file line by line and check for the data that you are interested in. Remember a text file is just a stream of characters with no structure so you cannot easily use file positioning to get to a particular item.

          1 Reply Last reply
          0
          • N NaumanMalik

            Hi, How are you?...i hope you are doing fine... i want to ask is there any built in function to get on exact line in a file? Like: FILE DATA: 1)Start 2)Mid 3)Username 4)END i want to get the pointer of file handler on 3 so that i can read that specific line.... or Can we use Seekg.(); function in this case? Kindly help please

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            If you have questions or comments then please use the Reply link, not the Email.

            N 1 Reply Last reply
            0
            • L Lost User

              If you have questions or comments then please use the Reply link, not the Email.

              N Offline
              N Offline
              NaumanMalik
              wrote on last edited by
              #6

              but i want to privately message you dont want leak my code please check the inbox kindly ... Thank you

              L Greg UtasG D 3 Replies Last reply
              0
              • N NaumanMalik

                but i want to privately message you dont want leak my code please check the inbox kindly ... Thank you

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Sorry, all help provided by CodeProject members is done in public through the forums on this website. If you want private help then you are in the wrong place.

                1 Reply Last reply
                0
                • N NaumanMalik

                  but i want to privately message you dont want leak my code please check the inbox kindly ... Thank you

                  Greg UtasG Offline
                  Greg UtasG Offline
                  Greg Utas
                  wrote on last edited by
                  #8

                  Oh, this explains why I got an email that contained code but couldn't find the same message on this board. Sorry, I don't do code inspections. If you don't know how to use a debugger, you need to learn now. The days when I wrote code with very few errors are gone. I wouldn't be able to do anything without a debugger now. They're so much better and easier to use than they were 40 years ago that I just focus on the design and then use the debugger to fix the details that I got wrong. :-D

                  Robust Services Core | Software Techniques for Lemmings | Articles

                  <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                  <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                  N 1 Reply Last reply
                  0
                  • Greg UtasG Greg Utas

                    Oh, this explains why I got an email that contained code but couldn't find the same message on this board. Sorry, I don't do code inspections. If you don't know how to use a debugger, you need to learn now. The days when I wrote code with very few errors are gone. I wouldn't be able to do anything without a debugger now. They're so much better and easier to use than they were 40 years ago that I just focus on the design and then use the debugger to fix the details that I got wrong. :-D

                    Robust Services Core | Software Techniques for Lemmings | Articles

                    N Offline
                    N Offline
                    NaumanMalik
                    wrote on last edited by
                    #9

                    Okay may be i disturbed everyone here for nothing... I'm really sorry for stupid questions. I do actually know how to debug you sir when you get stuck only then you ask for help... but that debugger get the job done after 7 hours :| ... and Richard's steps may be helpful but it is very difficult for me to understand it you know... Anyways Thank you for your help, i appreciate your help ;)

                    1 Reply Last reply
                    0
                    • N NaumanMalik

                      but i want to privately message you dont want leak my code please check the inbox kindly ... Thank you

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      If you can't write a function to search for a specific character in a text file, ('\n'), counting how many times you see that character, your code isn't worth hiding.

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups