lewashby 56 Junior Poster

I ran the command ifconfig and in addition to lo and eth0 I got this item that I have never seen before. Can anyone tell me what it is?

virbr0 Link encap:Ethernet HWaddr da:1c:6c:2a:cb:80
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lewashby 56 Junior Poster

Thanks. It worked but it took me a while. I had to run apt-get update first. I alwasy forget that after I've just installed a new server. Since we're on the subject, why do simple apt-get commands not work until upate has been run?

lewashby 56 Junior Poster

Why do you say that Mint cripples the command line?

lewashby 56 Junior Poster

I tried to run ./configure on a small program that the Linux book I'M reading instructed me to download and I got the error "no acceptable C compiler found in $PATH" I then tried to run atp-get install gcc, but then I got "unable to locate package gcc". Any dieas?

lewashby 56 Junior Poster

Is there a way I an compress a file in Linux for Windows? I recently sent a compressed folder to a Windows recipient and I don't think they were able to open the file.

lewashby 56 Junior Poster

Wow, I'M really dizzy now. Thanks. The one larg mental block I have here is that I do not understand the heap. I know that it exist and that the syntax for placing variables on the heap is the new key word and I only know that because someone told me or I read, hey, there's a place in memory called the heap and you can access it using new. Other than that I have no idea when, how, or why I would need to do such a thing. Thanks again for your help I'M going to start looking it over and trying it out on my program.

lewashby 56 Junior Poster

Why would a teacher be asking the question? I don't get it. I'M not in School, I'M being taught by a programmer/Linux admin who's been willing to give me his time.

lewashby 56 Junior Poster

Below is the code. The output is working fine if the number of digits in argv[1] is evenly divided my 3 but when it not evenly divided by 3 I'M getting the core dump error. What I'M trying to do here is add "0" to the left portion of argv[1] when the number of digits in argv[1] is not evenly divded by three.

123 -> GOOD, 1234 -> 001234, 12345 -> 012345

Also note that I can not use any kind of build in string class. Also, what I'M aksing is only one small problem in the overall of what I'M trying to do, this is not the assignment itself, so I'M not asking anyone to do my homework.

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "functions.h"

int main(int argc, char *argv[200])
{
    int number = atoi(argv[1]);
    int numberOfGroups;
    int numberLength = strlen(argv[1]);

    std::cout << number << std::endl << numberLength << std::endl;

    numberOfGroups = get_groups(numberLength);

    std::cout << "the number of groups is " << numberOfGroups << std::endl;

    while ( numberLength / 3 != numberOfGroups || numberLength < 3 )
    {
        strcat("0", argv[1]);
    }
    std::cout << "The number is " << argv[1] << std::endl;

    return 0;
}

// FUNCTIONS

int get_groups(int length)
{
    int groups = 0;

    if ( length <= 3 )
    {
        groups = 1;
    }
    else if (length % 3 != 0 && length)
    {
        groups = (length / 3) + 1;
    }
    else if (length % 3 == 0 && length)
    {
        groups = length / 3;
    }
    return groups;
}
lewashby 56 Junior Poster

Okay, so now I'M having a error: incompatible types in assignment of ‘char’ to ‘char [13]’ problem. Does the char argv[1] come in as a c style string? If not, how can I convert or copy it into a C-style string?

lewashby 56 Junior Poster

The guy teaching me wants me to use c style strings and I was also told to stay away from classes completly until he's ready for me to move in that direction. Thanks though, I'M going to see if I can revise the code. I may post back here if I am still having trouble.

lewashby 56 Junior Poster

Segmentation fault (core dumped)

Can someone please explain what that error message means? I'M tryin to use strcat() to add "0" to the left end of char *argv[1] I want it to do this only when the lenth of argv[1] can not evenly be divided by 3. So if I get 123 all is well, but if argv[1] is 1234 I need to append a "0" to the left. When I run the program rather than append the "0" it's giving me that error, and it's only doing that when the number is not a multiple of 3. Thanks.

lewashby 56 Junior Poster

Thanks everyone and thanks mike for the program. I'M going to go compile that right now.

lewashby 56 Junior Poster

You you please give me a VERY simple example on using more than one star * with a pointer so I can better understand it and see how it might be useful? And by simple I mean as close to hello world as you can get so I don't have anything else consusing me or throwing me off. Thanks all, you've been very helpful.

lewashby 56 Junior Poster

I have been told that in C++ the concept of a string does not exist. A string is just an array of type char. So in the following code, is message an array because it doesn't really look like one?

char *message = "I am having trouble understanding pointers";
std::cout << message

The line above does not really resembel an array to me, is this just a short way of saying
char *array[] = "some stuff";

I'M also confused by the line char *members[4] = {"Sally", "Alex", "George", "Martha"};
I thought that the number in the [] of a char array would dictate how many characters are in the array but in this case it's how many strings all together. What have I missed here.

Lastly, I can write a very very small pointer program that changes the value of x and then cout << x and accuratly predict the output but anything more compicated than that I'M completly lost. I don't understand the relationship between pointers and arrays nor do I understand any pointer that begins with more than one *. Thanks for any and all help.

lewashby 56 Junior Poster

NathanOkiver, I thought so too but that's the way my book and in down. The weird thing is several lines later when the paragraph was talking about the previous code it referenced that piece of code as being \0. But the program worked anyway so what the hell. Thanks everyone, it's clearer now.

lewashby 56 Junior Poster

In the following program how or the two while statements working, while(szTarget[targetIndex]) & while(szTarget[targetIndex]) since the their first element is initialized to zero? Zero is false and one is true so how are they getting even one iteration?
The book I'M reading also made a point of saying this:

"It is very tempting to write C++ statements such as the following":

char dash[] = " - ";
concatString(dash, szMyName);

"This doesn't work because dash is provided just enough room to store four characters. The function will undoubtedly overrun the end of the dash array." <- What do the mean by that? I thought arrays were not changable anyway so how are they running lines like szTarget[targetIndex] = szSource[sourceIndex] in the first place, wouldn't this be editing the array szTarget[]?

lewashby 56 Junior Poster

Thanks all.

lewashby 56 Junior Poster

Thanks. So there's now way to look inside std and cout and width for myself?

lewashby 56 Junior Poster

I'M reading "C++ FOR DUMMIES" 4th edition by Stephen Randy Davis and the chapter on arrays as just introduced this line -> cout.width(3); with absolutly no explanation to waht width is. I would like any of you guys to help me wout here but in addition to telling what .width is please also explain to me how I can find this kind of info out on my own. I know that cout is part of std but I don't really understand std. As far as I know it's a library that I've not seen nor do I know where to find it. But knowing that cout is part of std and that width was acccessed through cout, I'M assuming that if I can see into std I could find out for myself what width is.

lewashby 56 Junior Poster

Thanks. But I've been told that I'M not to use classes right now. So I'M pretty much doing C style code in C++. I'll take a look at your link.

lewashby 56 Junior Poster

How can I grow the size of a char array?

char myArray[6];

Assumming that all the current elements are occupied how can I add more empty element to the array to input another value into?

lewashby 56 Junior Poster

I was trying to avoid hard coding MyPrg.cpp and MyPrg. I was going to use ${1} for command line arguments. So I would simply type "compile MyPrg.cpp" and my script would run g++ -g -Wall ${1} -o ${1 - last 4 characters}

lewashby 56 Junior Poster

I'M wanting to write my own command/script for compiling my c++ files. I use g++ -g -Wall filename.cpp -o filename

I'M trying to figure out how I can trip of the last four characters (.cpp) from a string. Any ideas?

lewashby 56 Junior Poster

I'M trying to get a page like this one -> http://1stbytes.com

To behave like this one -> http://www.graceworkskids.com/index.html

when the browser is resized.

lewashby 56 Junior Poster

My css file is size.css and it contains -> body { width: 100%; }
My html file is below. I can not see a difference between using and not using the css file. I'M trying to get everything on the page to get smaller(including images) and reduce down into one column.

HTML files.

<html>
<head>
<link href="size.css" rel="stylesheet" type="text/css" media="screen">
</head>
<body>
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
fawoiejfiowjeiofjweiojfiowejfiowejfiowejfioewjiofjewoijfoiwejfioejwiofjweiojfoiejfoijweiofjiowejfioejfiojewiofjioewjfoiewjifjoifjoijfweiojfeioj<br />
</body>
</html>
lewashby 56 Junior Poster

I added this line <link href="a_data/resize.css" rel="stylesheet" type="text/css" media="screen"> to my html code and this line body { width: 100%; } to my resize.css file but I couldn't see a difference.

lewashby 56 Junior Poster

How would I take a liquid layout from a site such as http://www.graceworkskids.com/index.html

and use that same design style on a sitle like http://1stbytes.com/

What am I looking for in he html code?

lewashby 56 Junior Poster

Note that I am using MinLinux. I'M trying to launch Team Fortress 2 from Valve's Steam and I'M getting the following error.

Required OpenGL extension "GL_texture_compression_s3tc" is not supported. Please install S3TC texture support.

I checked my Synaptic Package Manager and I already have the following two packages installed when I enter s3tc into the text field of the SPM.

libtxc-dxtn-s2tc-bin
&
libtxc-dxtn-s2tc0

The only one listed as not installed was libtxc-dxtn-s2tc-dev

Any ideas? Thanks.

lewashby 56 Junior Poster

I use Mint Linux. What do I need to get in order to get started programming in java? Is there a particular IDE that is good for Java or should I just stick with vi(m)? My skill level is as follows. Iv succesfully written a date validation program in C++ and bash shell script and I've written "number input to sentence program" in bash and I'M currently writting it in C++ as well.

lewashby 56 Junior Poster

mike, I don't think I can hard code something like setw(6) because I have no way of knowing how large of a number the user might enter into the program. I am also unfamilar with stringstream or unsigned

Moschops I got the following error when I tried you code.

NumbersToStrings.cpp:34:13: error: request for member ‘insert’ in ‘strNumber’, which is of non-class type ‘char*’

char *strNumber = argv[1];

strNumber.insert(0,"0");

deceptikon, your method compiled just fine but didn't actually change the output of the number. If I entered 12345 it would still out put 12345 rather than 012345 which is what I'M trying to get.

lewashby 56 Junior Poster

Is there a danger of data loss when encrypting information?

lewashby 56 Junior Poster

Does anyone know how I can add "0" to the left side of a string? If I get "1234" I'd like to make it "012345", if I get "1234" I'd like to make it "001234". Any suggestions?

lewashby 56 Junior Poster

In the following test case program I'M trying to figure out how I can use the remainder of divison to make a decision but I can not seem to get this test case to respond in the way that I think and want it to respond based upon the remainder of dividing two command line arguments (linux). It never out puts either one of my cout statements even when I'M feeding it 3 & 7 or 3 & 8.

Here's the program:

#include <iostream>
#include <stdlib.h>

int main( int argc, char* argv[] )
{
    //number1 = atoi(argv[1]);
    //number2 = atoi(argv[2]);

    if ( atoi( argv[1] ) % atoi( argv[2] ) == .33333 )
    {
        std::cout << "33333" << std::endl;
    }
    else if ( atoi( argv[1] ) % atoi( argv[2] ) == .66667 )
    {
        std::cout << "66667" << std::endl;
    }

    return 0;
}
lewashby 56 Junior Poster

Thanks guys. It's working.

lewashby 56 Junior Poster

Well, I tried the following and it approved 1985 as a leap year. So id did not work.

if ( local_year % 4 == 0 && ( local_year % 100 != 0 || local_year % 400 == 0 ) );

lewashby 56 Junior Poster

Can anyone tell me whay the following funtion that should be returning true if the year is leap year and false if it is not, is givign me unexpected results? when I entered 1985 I got true? when I entered 2012 I got false. When I entered 2000 I got true, it was actually right on that one. I'M building a program that will validate if a date is valid or not based on the number of days in each month, I need leap year to determin the max days in FEB, etc... I frist wrote the program in bash and it worked just fine. Now that I've converted the formula over to C++ it's not working out.

bool is_leap_year( int year )
{
    bool result = false;
    int local_year = year;

    if ( 0 == (( local_year % 4 ) && 0 != ( local_year % 100 )) || 0 != ( local_year % 400 ) )
    {
        result = true;
    }

    return result;
}
/*END*/
lewashby 56 Junior Poster

Just got a 16 GB PNY flash drive from Wal-Mart and formatted it to ext4. Any idea how I could put access security on the drive? I would prefer security to protect against other OSs as well. Thanks.

lewashby 56 Junior Poster

Thanks. I thought char was a data type for a one character string. But it's been a while since i played with C++ and I'M just now trying to get back into it. One more thing. How might I create a variable to hold one of the argv[] elements that a number/string into an int? One last thing, what is the relevence of the * for the char variable? Thanks again.

lewashby 56 Junior Poster

In code like int main(int argc, char **argv), I'M trying to understand command line arguments a little better. And what would be the difference between char ** argv & char * arg[]? Thanks.

lewashby 56 Junior Poster

Thanks guys, you've been a big help. Got this small part of the program working now.

lewashby 56 Junior Poster

Thanks gusy but I am getting these two errors. Any idea?

DateValidation.cpp:8:24: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
DateValidation.cpp:9:34: error: ‘strlen’ was not declared in this scope

Here's the program.

#include <iostream>
#include <string>
#include "functions.h"

int main( int argOne, char **ArgList )
{
    //std::cout << ArgList[1] << std::endl;
    int number = ArgList[1];
    int digits = strlen( ArgList[1] );
    std::cout << digits << std::endl;

/*  if ( digits == 8 )
    {
        std::cout << "Number of digits is good" << std::endl;

        int month = 1;
        int day = 2;
        int year = 3;
    }   
    else
    {
        std::cout << "Invalid number of digits" << std::endl;
    }*/
    return 0;
}

// FUNCTIONS

int getNrDigits( int my_int )
{
    int local_int = my_int;
    int count = 0;

    while ( local_int > 0 )
    {
        local_int /= 10;
        count++;
    }
    return count;
}
lewashby 56 Junior Poster

Thanks it worked gusy. Now I will be receiving date as a command line argument (linux). I've never done that with c++ and from what I've been able to find via the internet I need to use int main( int arg, char **arg2 ) any idea on how I can get my date value into my variable date from the command line? Thanks again guys.

lewashby 56 Junior Poster

VernonDozier, this program will be assuming that the user is entering a 0 if the month is before October. Thanks for the help everyone, I'll try and emplement some of your suggestions. Only now I need to change date to a char **arg variable so now I'M going to have to twik it even more. This program is to be a date validation program. I recently wrote the whole thing in bash and it worked. I thought it would be easier to simply move the program from a bash copy to a C++ copy, I was wrong!

lewashby 56 Junior Poster

In the program below I need to get month to hold the first two digits of date, day two hold the digits 3 & 4, & year to hold the last four digits. Any idea on how I can accomplish that?

#include <iostream>
#include <string>
#include "functions.h"

int main()
{
    std::cout << "Please enter a number. ";
    int date = 0;
    std::cin >> date;
    int digits = getNrDigits( date );

    if ( digits == 8 )
    {
        std::cout << "Number of digits is good" << std::endl;

        int month = 1;
        int day = 2;
        int year = 3;
    }   
    else
    {
        std::cout << "Invalid number of digits" << std::endl;
    }
    return 0;
}

// FUNCTIONS

int getNrDigits( int my_int )
{
    int local_int = my_int;
    int count = 0;

    while ( local_int > 0 )
    {
        local_int /= 10;
        count++;
    }
    return count;
}
lewashby 56 Junior Poster

I'M getting a "DateValidation.cpp:10:2: error: ‘numberOfDigits’ was not declared in this scope" error. Here is my call to the function: numberOfDigits = getNrDigits( int date );

The function is declared in the file functions.h and I have #include "functions.h" at the top of my page. Any ideas?

lewashby 56 Junior Poster

In the following program, when I enter a number I'M getting strange output back. When I enter 5 I get 0x6011a85 back on the cout << "you entered" line.

#include <iostream>
//#include "functions.h"

int main()
{
    std::cout << "Please enter a number. " << std::endl;
    int date = 0;
    std::cin >> date;
    std::cout << "You entered" << std::cout << date;
}

// FUNCTIONS

/*int getNrDigits( int my_int )
{
    int local_int = my_int;
    int count = 0;

    while ( local_int > 0 )
    {
        local_int /= 10;
        count++
    }
    return count;
} */
lewashby 56 Junior Poster

I've been told to study up on four c segments: code, data, stack, heap. I know that googleing stack and heap will probably give me a mountain of information. But what the heck is code and data? If I type c code into google I'M going to get a lot of c source code and I don't think that is what I'M ment to study here. If I type c data I suspect I'M going to find a lot of pages concerning data types. When looking at the four secments of c, how can I research code & data? Thanks.

lewashby 56 Junior Poster

I need to store the number of digits from a number into a variable. e.g. 538, i need to store 3. How can I accomplish this is C++? Thanks.

lewashby 56 Junior Poster

In the following script I can't get the variable STARTPOINT to increment by 3 each time through the loop. I con't get it because the variable NUMBEROFGROUPS is incrementing by -1 each time and both increment lines look identical to me.

#!/bin/bash
set -x

leading_zeros() {
    local NUM=${1}
    local NUMBEROFDIGITS=${2}
    local NUMBEROFGROUPS=${3}

    while [[ $(( ${#NUM} / 3 )) -ne ${NUMBEROFGROUPS} ]] || [[ ${#NUM} -lt 3  ]]; do
        NUM="0${NUM}"
    done

    echo ${NUM}
}

read -p "Enter a number no higher than the billions range" NUM

NUMBEROFDIGITS=${#NUM}
NUMBEROFGROUPS=$( expr ${NUMBEROFDIGITS} / 3 )

if [[ ${NUMBEROFDIGITS} -lt 3 ]]; then # {
    NUMBEROFGROUPS=1
    NUM=$(leading_zeros ${NUM} ${NUMBEROFDIGITS} ${NUMBEROFGROUPS})
elif [[ `expr ${NUMBEROFDIGITS} % 3` -ne 0 ]]; then # } {
    let NUMBEROFGROUPS=NUMBEROFGROUPS+1
    NUM=$(leading_zeros ${NUM} ${NUMBEROFDIGITS} ${NUMBEROFGROUPS})
fi # }

while [[ ${NUMBEROFGROUPS} -gt 0 ]]; do # {
    STARTPOINT=0
    CURRENTGROUP=${NUM:${STARTPOINT}:3}
    echo ${CURRENTGROUP}

    let STARTPOINT=$(( ${STARTPOINT} + 3 ))
    let NUMBEROFGROUPS=$(( ${NUMBEROFGROUPS} -1 ))
done # }
lewashby 56 Junior Poster

I just wrote this program myself in bash. I created an array
CALENDER=(31 28 31 30 31 30 31 31 30 31 30 31)

Dealing with leap year is the trick part. If you want let me now and I'll supply my script.