Program run perfectly without error but cant show anything


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Program run perfectly without error but cant show anything
# 1  
Old 04-09-2015
Linux Program run perfectly without error but cant show anything

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

No problem,but it cannot show what I want

2. Relevant commands, code, scripts, algorithms:
wc test.cpp
wc test.cpp | ./test -l

3. The attempts at a solution (include all code and scripts):

Code:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main (int argc, char *argv[])
{
    string str;
    char *str1 = new char[80];
    int SUM=0,count=0;
    string fsize;
    int min=0,max=0;

    getline (cin, str);
    strcpy (str1, str.c_str());
    fsize = strtok (str1," ");
    if(argc==1){
            cout<<"Not enough arguements!";

    }

        for(int i=0;i<argc; i++){

                if(strcmp(str1,"-b")==1){

                    for (int m=0; m<=2; m++)
                        fsize = strtok (NULL, " ");
                    if (atoi(fsize.c_str()) > max) {
                        max = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    if (atoi(fsize.c_str()) < max) {
                        min = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    count++;}
                else if (strcmp(argv[i],"-l")==1){

                    for (int m=0; m<=2; m++)
                        fsize = strtok (NULL, " ");
                    if (atoi(fsize.c_str()) > max) {
                        max = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    if (atoi(fsize.c_str()) < max) {
                        min = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    count++;}
                else if (strcmp(argv[i],"-w")==1){

                    for (int m=0; m<=2; m++)
                        fsize = strtok (NULL, " ");
                    if (atoi(fsize.c_str()) > max) {
                        max = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    if (atoi(fsize.c_str()) < max) {
                        min = atoi(fsize.c_str());
                        SUM=SUM+max;}
                    count++;}
                else
                    cout<<"\nInvalid Input!\n";

                cout << "There are " << count << " files" << endl;
                cout << "Largest file has " << max << " bytes" << endl;
                cout << "Smallest file has " << min << " bytes" << endl;
                cout << "The ToTal is " << SUM  << endl;
	}
	return 0;

}


This is my program,what I want is do this program to check how many bytes,lines and words inside any of the file.
When I type wc test.cpp it will pop out
6 111 12608 test
But when I type wc test.cpp | ./test -l
it give me segmentation fault(core dumped)
Anyone can help me with this?

INTI/Interacting System
# 2  
Old 04-09-2015
Moderator's Comments:
Mod Comment The entire template must be completed; not just the 1st three questions!

The answer to question #1 in the template should be a clear statement of what your assignment is. What is your program supposed to do? Is it really supposed to be processing the output from a wc command, or are you supposed to be implementing a replacement for the wc utility?

Where is your program dropping core? What output do you get from you debugger when you give it your core file?

Please use CODE tags for all sample input, output, and code segments; not just your C++ code.

This thread is closed. Please open a new thread with the complete template fully filled in.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Error when run makefile to compile C program

I have a make file for C program, which always gives the error ld: 0711-738 ERROR: Input file ../src/file_name.o XCOFF32 object files are not allowed in 64 mode Does anybody know the problem? Thanks for contribution (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Can't get my program to run -- GC calculator?

have been trying for a few weeks not to get this program running. I am newer to programming and it has definitely been a challenge. I think my problem arises with my if statement. I can get it to append the name to the new file, but it simply appends the whole sequence to the file rather than... (3 Replies)
Discussion started by: haley6719
3 Replies

3. Shell Programming and Scripting

Run a program as another user

I have a bash script that launches another problem. I need to run that program under a certain user account. The script itself is run using 'sudo <scriptname>'. #!/bin/bash myprogram=... exec "$myprogram" How would this be done? (1 Reply)
Discussion started by: Carson Dyle
1 Replies

4. UNIX for Dummies Questions & Answers

Log in, run program

Hey, im editing the passwd file so that when the user ben logs in it runs my assign program. I changed the last column from to Then when i log in i get... There is no problem with the program because it runs fine when i open it normally. Any help much appreciated. (8 Replies)
Discussion started by: RAFC_99
8 Replies

5. OS X (Apple)

Log file to show if loginhook has run or not

Which log file lists the activity of startup scripts, particularly loginhooks? I am trying hard to find it and I cannot. How can I even tell if my script is running without errors if there isnt a log? Very frusturating! (1 Reply)
Discussion started by: glev2005
1 Replies

6. Shell Programming and Scripting

CRON is not working perfectly

I scheduled a cron job to run @ 1:00 as follows , 00 01 * * * /app/cbf/CLIF/version-1.0.0.0/scripts/archival.sh Please find the archival.sh script. But cron is throwing a mail stating sqlplus command not found So can anybody suggest what might be the problem ??? (13 Replies)
Discussion started by: manas_ranjan
13 Replies

7. UNIX for Dummies Questions & Answers

cannot run program

Hi, I have a program in /opt/local/bin, my path in my .profile is export PATH=/opt/local/bin:/opt/local/sbin:$PATH however when i type the program name it cannot find it, however i know the program is in /opt/local/bin? Thanks (2 Replies)
Discussion started by: c19h28O2
2 Replies

8. UNIX for Dummies Questions & Answers

How do i run a program while in Unix?....

Im new and wanted to know if im in the unix terminal and lets say i want to run microsoft word for example. i go in and go into the HD and then keep going and i type ls and see that microsoft word.app is there. how do i run it from that? (4 Replies)
Discussion started by: Corrail
4 Replies

9. UNIX for Dummies Questions & Answers

Getting a program to run

Please help, I have tried to run this program countless times and still nothing. Please tell me what I'm doing wrong. $ cat>test count=1 while do echo "5" read number echo $5 let count=count+ 1 done exit 0 ^C$ ksh test $ ^C $ ksh test $ $ nothing happend (6 Replies)
Discussion started by: ctiamaria
6 Replies

10. Programming

how to run debugging on c program

Can someone help me debug a c program I am running? It gives me segmentation fault. I want to turn on debugging. Can some one give the command to turn it on? Below is the error I get: Segmentation Fault (core dumped) (3 Replies)
Discussion started by: ibeg
3 Replies
Login or Register to Ask a Question