help with my program

This is a discussion on help with my program within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm making my own encryption code and I will post the part where I need help with:: This may ...

  1. #1
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    Exclamation help with my program

    Hey, I'm making my own encryption code and I will post the part where I need help with::


    This may be unproper but this is like the pre pre beta stage lol

    cout<<"Enter something you want to encrypt: "<<endl;
    cin.get(user, 100);
    cin.ignore(102, '\n');
    clrscr();

    do
    {
    user[x]=1;
    l++; x++;
    }

    while(x!=26);

    My question is I need to make the while statement know how many characters the user enters but I don't know how, is there a way to count how many characters the user types...This program is pretty crappy right now...i plan on making it letting u encrypt files and crap...but anyway if someone knows.... THanks


    Also if you have any suggestions that would be great

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    use strings in the std string header.

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    This -

    char arr[256];
    cout << "chars: " << cin.get(arr,256).gcount();

    or you could use strlen() on the string, or as golfinguy4 has stated use std::string which has a member function which will return the length.

  4. #4
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    Originally posted by Sorensen
    This -

    char arr[256];
    cout << "chars: " << cin.get(arr,256).gcount();

    or you could use strlen() on the string, or as golfinguy4 has stated use std::string which has a member function which will return the length.
    What would go in the while part of the do? I am pretty new...Im only in computer programmin II in my school

  5. #5
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    I didn't realise this was a school assignment, sorry. In that case we need to change -

    >My question is I need to make the while statement know how many characters the user enters

    to

    >The question I've been given is I need to make the while statement know how many characters the user enters

    In which case something like this would work -

    char arr[256];
    cin.get(arr,256);
    int j=0;
    while(arr[j])
    j++;

    'j' will contain the amount of characters entered minus the '\n'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21