gerard4143 371 Nearly a Posting Maven

Then pass it as a reference.

Something like this

#include <iostream>
#include <string>

void replaceAll(const std::string & oldString, const std::string & newString, std::string & original)
{
    size_t n = 0;
    while ((n = original.find(oldString, n)) != std::string::npos)
    {
        original.replace(n, oldString.size(), newString);
        n += newString.size();
    }
}
int main(int argc, char** argv)
{
    std::string foo("T44 T44 T44 bar");

    replaceAll("T44", "4/4", foo);

    std::cout << foo << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

Well the question I would ask is - Do you want to modify a variable past to this function or do you want to return a variable created by this function?

gerard4143 371 Nearly a Posting Maven

Since replaceAll() returns void and doesn't change any global variables or state. What does this function accomplish?

gerard4143 371 Nearly a Posting Maven

Instead of looping throught the arrays, I would try a function like memcmp().

gerard4143 371 Nearly a Posting Maven

Do you mean something 'ugly' like this?

#include <iostream>

template <class T>
class me
{

public:

    me():t(0) {}

    void create_T_pointer(const T & v) { t = new T(v); }

    const T* get_data() const { return  t; }

private:

    T * t;

};

template <class T>
std::ostream& operator <<(std::ostream & out, const me<T> & m )
{
    if ( m.get_data() )
        return out << *m.get_data();
    else
        return out << "Null pointer" << std::endl;
}

int main(int argc, char** argv)
{
    me<int> you;

    std::cout << you << std::endl;

    you.create_T_pointer(1234);

    std::cout << you << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

Do you mean a data member which is a template?

gerard4143 371 Nearly a Posting Maven

One small subtle point.

fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.

gerard4143 371 Nearly a Posting Maven

How the hell would we know what you forgot?

gerard4143 371 Nearly a Posting Maven

This forum is not a free tutoring service or a homework completion site. Post your question clearly, post your code clearly indicating where the problem is and post any other pertinent information or data.

gerard4143 371 Nearly a Posting Maven

I think you'll find the answer here. Check the example.

http://www.cplusplus.com/reference/istream/basic_istream/seekg/

gerard4143 371 Nearly a Posting Maven

It doesn't. It only totals Sunday's sales. If you want an average then you'll have to divide by 50 or have a running day count to divide with.

gerard4143 371 Nearly a Posting Maven

So I'm assuming that a line represents a week and each integer from left to right represents days - SMTWTFS.

You should be able to sum the array elements over the array choc[50][7] by holding the day constant. example

int sunday = 0;

for (size_t i = 0; i < 50; ++i)
    sunday += choc[i][0];
gerard4143 371 Nearly a Posting Maven

While I'm waiting for the text file snippet

for (i=0; i<=50-1; i++)
for (j=0; j<=7-1; j++)
{}

//should be

for (i=0; i < 50; i++)
for (j=0; j < 7 ; j++)
{}
gerard4143 371 Nearly a Posting Maven

Could you post an example of the text file chocolates.txt?

gerard4143 371 Nearly a Posting Maven

Last hint.

#include <iostream>

unsigned long vowels(char ca[])
{
    if ( ca[0] == '\0' )
        return 0;
    //decide if ca[0] is a vowel
    return 1 + vowels(++ca);
}

int main(int argc, char** argv)
{
    char str[] = "This is a string to check for vowels";
    std::cout << "'" << str << "'" << " has " << vowels(str) << " characters" << std::endl;
    return 0;
}
gerard4143 371 Nearly a Posting Maven

Here's a big hint which counts the characters.

#include <iostream>

unsigned long vowels(char ca[], unsigned long v_num)
{
    if ( ca[0] == '\0' )
        return v_num;

    vowels(++ca, ++v_num);
}

int main(int argc, char** argv)
{
    char str[] = "This is a string to check for vowels";

    std::cout << "'" << str << "'" << " has " << vowels(str, 0) << " characters" << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

The GCC compiler has a switch -std which can determine the language standard.

Try searching this link for the -std switch options.

http://linux.die.net/man/1/gcc

gerard4143 371 Nearly a Posting Maven

So what is a ArrayList?

gerard4143 371 Nearly a Posting Maven

Yeah, my bad. I was wrote the reply too fast.

gerard4143 371 Nearly a Posting Maven

Why? Because C++ demands that functions are defined before they are used but you can define your functions like so.

double fIntoCm(double);

int main()
{
...
}

double fIntoCm(double dIn)
{
     double dCm;
     dCm = dIn*2.54;
     return (dCm);
}
gerard4143 371 Nearly a Posting Maven

You two errors on line one

for (index = 1; index < SIZE; ++);

for (index = 1; index < SIZE; ++index)
{...}
gerard4143 371 Nearly a Posting Maven

Here's a hollow square. I think?

#include <iostream>

int main(int argc, char** argv)
{
    unsigned int count = 12;

    for (size_t i = 0; i < count; ++i)
    {
        if ( i == 0 )
        {
            std::cout << std::string (count, 'x') << std::endl;
            continue;
        }
        if ( i == count - 1 )
        {
            std::cout << std::string (count, 'x') << std::endl;
            continue;
        }
        std::cout << 'x' << std::string (i - 1, ' ') << std::string (count - i - 1, 'y') << 'x' << std::endl;
    }

    return 0;
}



xxxxxxxxxxxx
xyyyyyyyyyyx
x yyyyyyyyyx
x  yyyyyyyyx
x   yyyyyyyx
x    yyyyyyx
x     yyyyyx
x      yyyyx
x       yyyx
x        yyx
x         yx
xxxxxxxxxxxx
gerard4143 371 Nearly a Posting Maven

I would go with an array of structures

struct personal
{
    std::string name;
    std::string phone;
    std::string DOB;
};

personal per[10];
gerard4143 371 Nearly a Posting Maven

The basic way is to save the input into a string and then check each character for validity.

gerard4143 371 Nearly a Posting Maven

Your first example should work if the for loop terminates when i = 5.

char str1[5] = "code";
char str2[5] = "code";

for(i; i < 5; i++)
{
printf("The array length is %c %c :\n", str1[i], str2[i]);
} 
gerard4143 371 Nearly a Posting Maven

No. You have to take the source code over to a Windows compiler and recompile it into a Windows exe.

gerard4143 371 Nearly a Posting Maven

Should this have a reference to int?

void ShowMenu(string& word, int choice);

Something like.

void ShowMenu(string& word, int & choice)
gerard4143 371 Nearly a Posting Maven

You could try something like this:

void check_string(const std::string str) { std::cout << "Got->" << str << std::endl; }

void print_actors_movies(treePtr root, const std::string name)
{
  if(root == NULL) return;

  if (root->left) print_actors_movies(root->left, name);

  std::for_each(root->actors.begin(), root->actors.end(), check_string);

  if (root->right) print_actors_movies(root->right, name);
}

I'll leave it to you to check if the name matches.

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven
int chdir(const char *path);

You can use chdir() which is in the unistd.h header file.

strRusty_gal commented: Thanks!~ +2
gerard4143 371 Nearly a Posting Maven

I would use a running total getting the strlen of line.

gerard4143 371 Nearly a Posting Maven
#include <iostream>

int main()
{
    //prompt for integers
    //read/extract integers into variables
    //do calculations
}
gerard4143 371 Nearly a Posting Maven

That's the gets() that all the C docs warns against using?

From my manpages...

Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

gerard4143 371 Nearly a Posting Maven

Do you mean const char array?

gerard4143 371 Nearly a Posting Maven

You have this

gcc -std=c++11 -std=c++0x -W -Wall tt1.cpp

but should it be

g++ -std=c++11 -std=c++0x -W -Wall tt1.cpp

gerard4143 371 Nearly a Posting Maven

Maybe I missed it. Where is the question? Are you asking us to write this program for you?

gerard4143 371 Nearly a Posting Maven

No, I want to inistialize the vector from inside the constructor initialization list the goal is not to use the constructor body too, only from the list

I thought I was doing that in my example.

gerard4143 371 Nearly a Posting Maven

Are you talking about something like this?

#include <iostream>
#include <vector>
#include <iterator>

template <class T>
class test
{

public:

    test(T a[], size_t s):vec(a, a + s ) {}

    void display_vec() const
    {
        std::copy(vec.begin(), vec.end(), std::ostream_iterator<T>(std::cout, " "));
    }

private:    

    std::vector<T> vec;

};

int main(int argc, char** argv)
{
    unsigned long mya[] = {1,4,5,7};
    test<unsigned long> you(mya, sizeof(mya)/sizeof(unsigned long));

    you.display_vec();

    return 0;
} 
gerard4143 371 Nearly a Posting Maven

Are you looking for a default constructor which will initialize the std::vector member with the values 1, 4, 5 via the constructor initialization list without embracing the C++11 features?

gerard4143 371 Nearly a Posting Maven

Not sure what your problem is. Are you trying to accomplish something like this?

server.c

#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>

#define DEFAULT_PROTOCOL 0
#define PORT 50000
#define MSG "\nGot the message!\n"

int main(int argc, char**argv)
{
    int listenfd, connfd, val = 1;
    char recvline[BUFSIZ + 1];
    struct sockaddr_in servaddr;

    signal(SIGCHLD, SIG_IGN);

    if ((listenfd = socket(AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL)) < 0)
    {
        perror("socket");
        exit(EXIT_FAILURE);
    }

    setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(PORT);
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);

    if ((bind(listenfd, (const struct sockaddr*)&servaddr, sizeof(servaddr))) < 0)
    {
        perror("bind");
        exit(EXIT_FAILURE);
    }

    if ((listen(listenfd, 5)) < 0)
    {
        perror("listen");
        exit(EXIT_FAILURE);
    }

    for (;;)
    {
        connfd = accept(listenfd, NULL, NULL);

        if (fork())
        {
            close(connfd);
        }
        else
        {
            int n = 0, i = 0;

            close(listenfd);

            while ((n = read(connfd, &recvline[i], (BUFSIZ - i))) > 0)
            {
                i += n;
            }
            recvline[i] = '\0';

            fprintf(stdout, "Server rec'd->%s\n", recvline);
            write(connfd, MSG, strlen(MSG));

            close(connfd);
            exit(EXIT_SUCCESS);
        }
    }

    exit(EXIT_SUCCESS);
}

client.c

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>

#define DEFAULT_PROTOCOL 0
#define PORT 50000
#define MSG "This is the message\n"

int main(int argc, char**argv)
{
    int clientfd, tot = 0, n = 0;
    char recvline[BUFSIZ + 1], rsp;
    struct sockaddr_in servaddr;

    if ( argc != 2 )
    {
        fputs("Usage error - a.out <IPaddress>\n", stderr);
        exit(EXIT_FAILURE);
    }

    while ( true )
    {
        fputs("Do you want to send a msg?(y/n)->", stdout);
        fscanf(stdin, "%c", &rsp);

        if …
gerard4143 371 Nearly a Posting Maven

Here's a correction implementing some of the changes mentioned above

#include <iostream>

class Base
{
public:
  Base() {}
  ~Base() {}
  void doSomrthing() {}
};

class MyCLass : public Base
{
  std::string name;
public:
  MyCLass();
  ~MyCLass();
  void init();
};

MyCLass::MyCLass()
{
  init(); //runtime error occurs with this line
}

void MyCLass::init()
{
  name = "MyClass";
  doSomrthing();
}

int main()
{}
gerard4143 371 Nearly a Posting Maven

Could it be this

Class

Please note the uppercase C

Or could it be the missing semi-colon here

class Base
{
  Base();
  ~Base();
  void doSomrthing();
}

Or here

Class MyCLass : public Base{
std::string name;
MyCLass();
~MyCLass();
void init();
} 
gerard4143 371 Nearly a Posting Maven

strlen takes a character pointer as its parameter.

size_t strlen(const char *s)

gerard4143 371 Nearly a Posting Maven

Open your file(a.txt) and a temp file. Read the a.txt file writing the results to the temp file. If one of the characters to be written is B then write b first.

Finally, delete a.txt and rename temp to a.txt.

gerard4143 371 Nearly a Posting Maven

Try something like this

#include <iostream>
#include <fstream>

int main()
{
    std::ofstream fout("outdata");

    for (size_t i = 0; i < 100; ++i)
        fout << "0x" << std::hex << i << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

Are you having problems with the ternary operator?

http://msdn.microsoft.com/en-us/library/e4213hs1%28v=vs.71%29.aspx

gerard4143 371 Nearly a Posting Maven

A better question would be -

Hi guys, I would like to know How to blink console text using Windows or Mac or Linux.

gerard4143 371 Nearly a Posting Maven

I would investigate pipes or popen.

Click Here

gerard4143 371 Nearly a Posting Maven

Are you looing for something like this?

#!/usr/bin/perl

use warnings;
use strict;
use autodie qw/open close/;

print "Enter input filename->";
chomp(my $ifilename = <STDIN>);

open(my $IFILE, "<", $ifilename);

while ( <$IFILE> )
{
    chomp;
    my @data = split(/\t+/, $_);
    print "@data\n" unless ( $data[3] eq $data[4] )#print this to another file
}

close($IFILE);

__END__
gerard4143 371 Nearly a Posting Maven

Since your using warnings and strict you should use my.

my $filesize = -s $filename;