lewashby 56 Junior Poster

I'm reading the book 'C++ Without Fear 2nd Edu' and I'm a little confused on the subject of shallow copies.
The book says the problems can arise if you make a shallow copy of an object and something happens to the original, goes out of scope, is deleted, etc... I don't get it. When a simple copy is made doesn't the new object get a member to member COPY of the value? The way the book makes it sound is as if the new object isn't a copy at all, it's just another pointer or reference to the same old object. That's the only way I see that something happening to the original object would affect the new. What am I missing here? Thanks.

lewashby 56 Junior Poster
#include <iostream>
#include <cstring>
using namespace std;

class String
{
    private:
        char *ptr;
    public:
        String();
        String(char* s);
        ~String();

        operator char*() { return ptr; }
        int operator==(const String &other);
};

int main()
{
    String a("STRING 1");
    String b("STRING 2");

    cout << "The value of a is: " << endl;
    cout << a << endl;
    cout << "The value of b is: " << endl;
    cout << b << endl;

    return 0;
}

String::String()
{
    ptr = new char[1];
    ptr[0] = '\0';
}

String::String(char* s)
{
    int n = strlen(s);
    ptr = new char[n + 1];
    strcpy(ptr, s);
}

String::~String()
{
    delete [] ptr;
}

int String::operator==(const String &other)
{
    return (strcmp(ptr, other.ptr) == 0);
}

In the program above I have a few questions.
My C++ book says that this line operator char*() { return ptr; } is what allows an object of this clas to be used with the stream operators << & >>. How is this since neither << nor >> are anywhere in that line as in other operator methods? Also, how is it that this operator does not show a return type before the method name, it just says operator?
My second questions is this line return (strcmp(ptr, other.ptr) == 0); these short hand line have always confused me. I believe this to be. if(strcmp(ptr, other.ptr) == ture) return 0; is that understanding correct?

lewashby 56 Junior Poster

I have ripped the TV show Pushing Daisies Blu-Ray disk as up to 3 episodes on one track. So now my ripped file is one file containing 3 episodes. Is there a good program that would allow me to split the file up into 3 different mkv files? Thanks.

lewashby 56 Junior Poster

That's actually the way I shut window$ every time already.

lewashby 56 Junior Poster

I've always been able to navigate through my Windows drive after booting up in my Linux OS but ever since I got Windows 8 there seems to only my a 50/50 change of a successful mount.

When I type this command
sudo mount -t ntfs -o uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000,dmask=0077,fmask=0177 /dev/sdd4 /media/garrett/Windows

I get this error
indows is hibernated, refused to mount.
Failed to mount '/dev/sdd4': Operation not permitted
The NTFS partition is in an unsafe state. Please resume and shutdown
Windows fully (no hibernation or fast restarting), or mount the volume
read-only with the 'ro' mount option.

mounting with RO, although it works it defeats the purpose of the mount.

I don't get it, Windows has been shutting down just fine.

I've also attached a picture of the error from the Desktop GUI in Linux Mint.

lewashby 56 Junior Poster

Thanks. As far as using a capital letter for a variable name I was only doing that because I noticed that my IDE was lighting up the variable names dict and list, I knew my code was written prior to python3 and I was thinging that python3 may had added some built ins named dict and list and could be causing me problems, so it was a last minute quick fix tryout. Thanks again.

lewashby 56 Junior Poster

When setting up an NFS server and setting up the 'ro' or 'rw' permissions, how do the ext4 permissions come into play? Thanks.

lewashby 56 Junior Poster
#!/usr/bin/env python3

tm = open('./timemachine.txt', 'r')
Dict = {}

for line in tm:
    line = line.strip()
    line = line.translate('!"#$%&\'()*+-./:;<=>?@[\\]^_`{|}~')
    line = line.lower()
    List = line.split(' ')

    for word in List:
        if word in Dict:
            count = Dict[word]
            count += 1
            Dict[word] = count
        else:
            Dict[word] = 1

for word, count in Dict.iteritems():
    print(word + ":" + str(count))

In the program above I'm getting the error -> builtins.AttributeError: 'dict' object has no attribute 'iteritems'
I'm following code that was given to me by the magazine Guru Guide / Coding Academy
Any ideas? Thanks.

lewashby 56 Junior Poster
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstring>

using namespace std;

class Fraction
{
    private:
        int num, den;       // numerator & demoninator
    public:
        Fraction() { set(0, 1); }
        Fraction(int n, int d) { set(n, d); }
        void set(int n, int d) { num = n; den = d; normalize(); }
        int get_num() { return num; }
        int get_den() { return den; }
        Fraction add(Fraction other);
        Fraction mult(Fraction other);
        Fraction(Fraction const &src);
        Fraction(char* s);
    private:
        void normalize();               // convert to standard form
        int gcf(int a, int b);          // greatest common factor
        int lcm(int a, int b);          // lowest common denominatro
};

int main()
{
    Fraction f1(3, 4);
    Fraction f2(f1);
    Fraction f3 = f1.add(f2);

    cout << "The value of f3 is ";
    cout << f3.get_num() << "/";
    cout << f3.get_den() << endl;

    Fraction a = "1/2", b = "1/3";
    //Fraction arr_of_fract[4] = {"1/2", "1/3", "3/4"};

    cout << "The value of a is ";
    cout << a.get_num() << "/";
    cout << a.get_den() << endl;

    return 0;
}

Fraction::Fraction(char* s)
{
    int n = 0;
    int d = 1;
    char *p1 = strtok(s, "/, ");
    char *p2 = strtok(NULL, "/, ");

    if(p1 != NULL)
        n = atoi(p1);
    if(p2 != NULL)
        d = atoi(p2);
    set(n, d);
}

Fraction::Fraction(Fraction const &src)
{
    cout << "Now calling copy constructor." << endl;
    num = src.num;
    den = src.den;
}

void Fraction::normalize()
{
    // handle cases involving 0

    if(den == 0 || num == 0)
    {
        num = 0;
        den = 1;
    }

    // put neg, sign in …
lewashby 56 Junior Poster

Edit it manually to say what. The python thing didn't work.

lewashby 56 Junior Poster

I would suggest Linux Mint, you can download it here -> http://blog.linuxmint.com/?p=2714

Learn how to navigate the file system, with relative and absolute paths.
Learn to edit config file with VIM, also with relative and absolute paths.
Learn how Linux mounts drives and how to mount them manually, then access that drive through the mounted directory.
When you're feeling really bold go through the Linux from scratch project. http://www.linuxfromscratch.org/

lewashby 56 Junior Poster
root@media-server:~# add-apt-repository ppa:nmi/vim-snapshots
-su: add-apt-repository: command not found
root@media-server:~# apt-add-repository ppa:passy/vim
-su: apt-add-repository: command not found
lewashby 56 Junior Poster

I just installed a headless Debian on my first that I'v ever built but I can't install any packages on it.

root@media-server:~# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package vim is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'vim' has no installation candidate

I get the same thing with pretty much any package I try to install. I have also already ran apt-get update
Any ideas? Thanks.

lewashby 56 Junior Poster

I just built my first computer and instlled headless on it. When I boot it up there are a few problems on the black and white screen with all the BS. It usually starts but it takes forever. All the parts are right out of the box via amazon and the OS is on an SSD. It takes the longest when it gets to this -> [#######] eth0: no IPv6 routers present

Where shouold I be looking for the log file at that would give me an idea as to whats going on? I'm assuming it's in /var/? but I'm not exactly sure where.

Thanks to any and all replies.

lewashby 56 Junior Poster

Thanks, I'll give it a try.

lewashby 56 Junior Poster

I just finished my first computer that I've ever built from the scratch. I used an MSI motherboard, AMD processor, DD3 RAM, and a Samsung SSD. I am wanting to install a headless Debian on it that I'll user for my in home media server but I'm having problems. I installed my Debian image onto a USB flash drive but when I boot the computer up with or without the USB drive in nothing happens, my monitor stays black. I'm not even getting a BIOS screen. Anyone have any suggestions on where to start troublshooting this? Thanks.

lewashby 56 Junior Poster

I use Banshee as my Media player and it works just find except that when I rip CDs into .wav files Banshee doesn't always get the ID3 information, artist, album, title, etc...
Any suggestion on a good CD ripper for Linux that does a better job at this. I would also like the ripper to rip my songs in the directory they need to go in. /home/me/Music/Artist/Album/Title.wav
Thanks for any and all suggestions.

lewashby 56 Junior Poster

I'm looking for a good printer/scanner that works well with Linux, any suggestions on brands and models? Thanks.

lewashby 56 Junior Poster

I just installed CentOS in my Oracle virtual box and now I'm having trouble getting it to connect online. I'm following the directions here -> http://xmodulo.com/how-to-configure-network-interfaces-in.html but the file ifcfg-eth0 is not showing up in /etc/sysconfig/network-scripts/ a lot of ther ifFILES are showing up but not that one. I would post the contents here but cut/past isn't working between my Mint Liunx desktop and my CentOS VM, even though I have turned that option on. My desktop is connected to the internet via my eth0 card and a network cable to my switch. Any ideas? Thanks.

lewashby 56 Junior Poster

Thanks.

lewashby 56 Junior Poster

I'm trying to install CentOS on my Linux Mint desktop through Oracle's VirtualBox. The instalation screen says it's installing to sda1 and that's it's mount points are /boot -> 500 MB, / -> 5.02GB, & 614 MB. Is this safe or is there a chance this is going to mess something up on my current desktop? I'v never installing anything through a virtual machine before. Thanks.

lewashby 56 Junior Poster

Thanks guys. mike_2000_17 one more thing, I thought gcc was for C and g++ was for C++ ?

lewashby 56 Junior Poster

[Linux]

I have had a hard time understanding pointers beyond a simple array step through and modifying one address at a time. When I get into pointers to C-structures, C++-objects and classes my head starts to hurt. And that's just to name a few. I find the C syntax *++p for instance to be very confusing, I would expect the syntax to look like this -> ++*p. Why on earth would the pointer symbol * be pushed back and be seperated from it's pointer name with the increment operator in the middle? Anyway, here's what I'm wanting to know. I've recently read that C++ 11 makes dealing with pointers a lot easier, if that's the case does the current version of g++ support that aspect of the new C++ 11 standard? Or better yet, what version of g++ supports it if any?

I also recently ordered a book called 'Understanding and Using C Pointers' from amazon and now I'm wondering if I really need that book if C++ 11 and g++ have a better way. Thanks.

lewashby 56 Junior Poster

If I am reading so many bytes at a time via read(number_of_bytes) or processing one line at a time via a loop, for line in file how will tell() behave? Will it still be giving me the position in the whole file or will it's positon be relative to what am processing in bytes or the current line?
I'm trying to process a .flac audio file. I need to find 'artist=', under any combination of caps or lowercase. Once I find that in the file how would I get the position of tell() to jump to the end of the '=' sign after 'artists='?
While I'm here, are there new lines in a binary files like a .flac file or is it just one giant line that only shows up as newlines for the screen?

import sys

file = open(sys.argv[1], 'rb')
tag_artist = b'artist='
artist_name = []

line = b''

position = 0
while tag_artist not in line.lower(): 
    line = file.read(15)
    print(file.tell())

print(line)
file.seek(675)
print(file.read(15))

Please do not mention other libraries that can do this for me.

lewashby 56 Junior Poster

if I have something like the following

file = open(filename, 'rb')

for line in file:
    #do stuff

Once I find what I'm looking for in file and it's placed in the line variable, how could I then capture that position withing file, not just line?

lewashby 56 Junior Poster

I have a few questions about libraries and header files. Since libraries are binary files and header file are source/text files why do they not just compile the header files along with the rest of the library files? It doesn't make sense to me to have libraries that are binary file and thus not editable but package them with source/text files that can be easily edited including edits that don't match the libraries they support.

Also. Since C the programming language is so small without the standard library how was the standard library created? How are any libraries created? I read that although a lot of GUI based programs are created in C, C is actually only capable of creating graphics with the aid of libraries, how are these libraries created?

lewashby 56 Junior Poster

Thanks. Can you tell me how to make gcc compile in c99 or c11? Again, this is on a Linux system.

lewashby 56 Junior Poster

[Linux & gcc]

I'm taking C courses and pluralsight.com and I'm both getting an error with a program I got from one of their videos as well as having some trouble understanding something in the code

#include <stdio.h>
#include <ctype.h>

int main()
{
    char message[] = "Hello world!";

    for(char *p = message; *p; ++p)
    {
        if(isupper(*p)) *p = (char)tolower(*p);
        else if(islower(*p)) *p = (char)toupper(*p);
    }

    printf(message);
}

When I try to compile this program in gcc I get this error ->

stringpointer.c:8:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for(char *p = message; *p; ++p)
     ^
stringpointer.c:8:5: note: use option -std=c99 or -std=gnu99 to compile your code
stringpointer.c:14:5: warning: format not a string literal and no format arguments [-Wformat-security]
     printf(message);
     ^

Also I'm having trouble understanding the for loop because I don't see a condition that says, if we hit '\0' we are done.

lewashby 56 Junior Poster

Is there a way to set an NFS shared directory to my recursivly chared via NFS, that directory including sub directories?

lewashby 56 Junior Poster

I'm currently building a headless Debian NFS media server and I'm doing most of my testing on my desktop. My cliant streaming device will by my "WD TV Live' TV streamer because it can read a Linux NFS network, I hate Samba. One of my problems is that the TV live will, via the internet, fetch the cover art for each movie title in my library but in order to do that it needs write access. I don't like the idea of giving my TV Live write access to my library for a number of reasons. My solution was to give the TV Live write access to one directory but store my movies in another. I then wrote a script in bash to read each file RO movies directory and create a link to it in my RW TV Live directory. My script worked and I can play the movies but for whatever reason my TV Live still can't write to the directory that I gave it write access to, both through NFS as well as through ext4 permissions. Here is the message I get when I try to fetch the meta data and cover art for each title
-> Unable to create media library. The selected source is configured ad Read-Only which prevents the WD TV from saving the media library.

Here is is the permissions to the library I'm sharing.
drwxrwxrwx 2 garrett garrett 4096 Jan 14 10:08 Videos1

And here is my /etc/exports file

# …
lewashby 56 Junior Poster

I assumed that udp was best for streaming and that's what I've heard Netflix uses because that's the only way they can steam at a reasonable speed with varying internet connections. I was hoping to use TCP inside my home network but connect via udp if I was going to stream my media from another location.

lewashby 56 Junior Poster

If you're creating a media server how do you control if the files are pushed out via tcp or udp? Or is that a client thing? I'm currently building a headless Debian media server and I was wonsering how that words. As far as streaming videos in my house either one would probobly be fine, but if I am streaming from outside my home network I would want udp to be utilized. I'm hosting the files from a Debian NFS server. Thanks.

lewashby 56 Junior Poster

When I delete files on any given file system like hard drives that I have mounted to my system or USB stick I get a directory that usualy named '.Trash-1000'. How does that directory work? Do I need to manually delete the .Trash-1000 directory because it might remain taking up storage or does it Linux overwrite anything that's place in that directory? Thanks.

lewashby 56 Junior Poster

Are there two versions of telent? Do I need to install telnet server on my Debian server and a telnet client on my desktop?

lewashby 56 Junior Poster

I don't know if this is a Linux Mint problem or a Debian problem. I use Mint as a desktop but I just installed a standard no GUI edition of Debian for my media server. I was going to use the Mint file browser Nemo to connect to the Debian server so it would be easier to copy files to and from but when I enter all the credintials into the connection box and click connect I get this error -> Host key verification failed
I can connect to the Debian server from my Mint desktop just fine through standard SSH.
I've always been able to connect to other systems through Nemo before, any ideas on what's going on? Thanks.

lewashby 56 Junior Poster

My compiler supports that function as an extension. What does that mean? I'm using gcc.

lewashby 56 Junior Poster

An offlien registry editor? Is that something that I download, burn onto a disk and reboot the laptop with the disk inserted.

lewashby 56 Junior Poster

Just got my nephew an HP Windows 8.1 laptop and either he can't remember the password that he just created or something is messed up. Is there a way to reset the password or do a hard reset if you can't even get logged in? Thanks.

lewashby 56 Junior Poster

In the following program it says that there is a conflict between my getline and the getline in stdio.h. I understand what it's saying because stdio.h has it's own getline function. What's confusing me is that this is the program that my programming book (The C Programming Language) is giving me to compile. Is there a way around this?

lewashby 56 Junior Poster

Well I sorta solved the problem. I was keeping my movies in /home/garrett/Videos/Movies and I had my NFS server set to share /home/garrett/Videos/ I wanted to do it that way hoping that I could then add other libraries like 'Shows under the Videos directory. For whatever reason that doesn't work and I have to specify exactly what directory to share because it doesn't share sub directories.

lewashby 56 Junior Poster

I was using the Linux Mint Flawless media server to host all my movie rips as .mkv files but I decided to go with a standard no GUI Debian server instead. I set up an NFS server to host my files with the most likely client to be my Western Digital TV Live streamer which is what I've always used to stream my movies from my computer to my TV. When I select a shared Linux server from my WD TV Live device it sees my NFS server and it displays the shared directory, but after selecting the directory I get this error. -> There is no media available for playback. This has always worked in the past on my Mint server through Samba but now it can't see any media on my Debian server using NFS. I really don't want to go back to Samba and I would prefer a standard bare bones server to the fancy Mint FLAWLESS server.

Here is a copy of my /etc/exports file

# /etc/exports: the access control list for filesystems which may be exported
#       to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/home/garrett/Videos *(rw,sync,subtree_check)

Any ideas?

lewashby 56 Junior Poster

I found the problem, it wasn't with my program it was my IDE. I navigated to the directory using the terminal and it executed just fine, only when I try to run it from Eclipse does it give me the error that there is not binary file.

lewashby 56 Junior Poster

Do you see any specific deprecated functions I've used?

lewashby 56 Junior Poster

I need to use the tar command to unpack a .tar.gz file and I need to do it from root but when the files unpack I want them to be owned by a specific user, not the root user. Can someone give me a hand?. I found the man pages confusing.

lewashby 56 Junior Poster

I'm using code from my sdl book and it doesn't seem to be a dated book. The book is using SDL 1.2 and I have that installed, but I may also have SDL2 installed and I don't know which version my program is linking to. Any ideas?

lewashby 56 Junior Poster

[Linux] Mint

I wrote the following code from an SDL book I have and it seems to be building just fine but when I go to run the program I get this error -> "Launch failed, Binary not found." I used Eclipse as my IDE and the setting are adjusted to the book's specifications.

Build feedback
10:56:43 **** Incremental Build of configuration Debug for project 2.1-Surfaces ****
make all
make: Nothing to be done for 'all'.

10:56:43 Build Finished (took 65ms)

Debug Directory Contents
main.d main.o makefile objects.mk sources.mk subdir.mk

Code

#include <SDL/SDL.h>

SDL_Surface *image = NULL;
SDL_Surface * backbuffer = NULL;

int main(int argc, char *argv[])
{
    // Init SDL
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        printf("SDL failed to initialize!");
        SDL_Quit();

        return 0;
    }

    backbuffer = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
    SDL_WM_SetCaption("SDL!!!", NULL);

    // load the image
    image = SDL_LoadBMP("graphics/image.bmp");

    if(image == NULL)
    {
        printf("Image failed to load!\n");
        SDL_Quit();

        return 0;
    }

    // draw the image
    SDL_BlitSurface(image, NULL, backbuffer, NULL);
    SDL_Flip(backbuffer);

    // wait
    SDL_Delay(3000);

    // finish
    SDL_FreeSurface(image);
    SDL_Quit();

    return 1;
}
lewashby 56 Junior Poster

Thanks mide_2000_17 I'm reading your artical now. I guess my question now is, do you now where in my system the sdl library I need would be at, on a Linux Mint system? I also have a few questions about some of the thing I read in your tutorial but all get with you later on those.

lewashby 56 Junior Poster

When I compile the following two programs one of them compiles and one of themse does not but I don't see a difference. The smaller program is the same only I've taken out a lot of the code so that I'm left with only the minimum that I need to display a window with SDL. I think it would be easier to learn with fewer lines of code and slowly learn the extra and more complicated aspects of using SDL.

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>

SDL_Surface* g_pMainSurface = NULL;
SDL_Event g_Event;

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_VIDEO);

    g_pMainSurface = SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT);

    return 0;
}

In the code above I'm getting this error -> Window.cpp|10|undefined reference to SDL_Init'|
Window.cpp|12|undefined reference to SDL_SetVideoMode'|

The following program compiles fine.

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>

SDL_Surface* g_pMainSurface = NULL;
SDL_Event g_Event;

int main(int argc, char* argv[])
{
    if(SDL_Init(SDL_INIT_VIDEO) == -1)
    {
        fprintf(stderr, "Could not initialize SDL!\n");
        exit(1);
    }
    else
    {
        fprintf(stdout, "SDL initialized properly!\n");
        atexit(SDL_Quit);
    }

    g_pMainSurface = SDL_SetVideoMode(640, 480, 0, SDL_ANYFORMAT);

    if(!g_pMainSurface)
    {
        fprintf(stderr, "Could not create main surface!\n");
        exit(1);
    }

    for(;;)
    {
        if(SDL_WaitEvent(&g_Event) == 0)
        {
            fprintf(stderr, "Error while waiting for an event!\n");
            exit(1);
        }

        // check the type of event
        if(g_Event.type == SDL_QUIT)
        {
            fprintf(stdout, "Quit event has occurred.\n");
            break;
        }
    }

    fprintf(stdout, "Terminating program normally.\n");

    return 0;
}
lewashby 56 Junior Poster

Gribouillis thanks, that worked perfectly.

lewashby 56 Junior Poster

I have I Brother Laser printer and it seems to be pring everytying just fine. But when I go print some property listings from a realesate company it all the sudden will not print at all and I get the following error. -> There was a problem processing documents 'flexmls'(job 11). Does anyone see anything that would suggest Linux incompatability? Image attached. bcea2376ebbe702e3e95b82f4aa26f1d