Creating and extracting archive file

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Creating and extracting archive file
# 8  
Old 03-04-2012
Thank you for your help guys, I have solved the issue but have a more interesting issue at hand.

The task is to create a c program that will check for a users input and then provide its length,the number of occurance of letters and the percentage of those letters.
E.g.
Input:
Hello Unix
Output:
Length of String: 9
Number of char h: 1
Number of char e: 1
Number of char l: 2
Number of char u: 1
Number of char n: 1
Number of char i: 1
Number of char x: 1

Percentage: of char h: 11.1%
etc

I have the following thus far:
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <ctype.h>

int BackGroundProgram()
{
    char ch;
    do
    {
        char YourWord[100],b=0; // Array for the word that will be used
        int i; // variable
        int number; 
        int letters;
        int length;
        printf("Enter string to calculate the length:\n");  //Asking for User Input
        scanf("%s",(YourWord)); // Scan for user input

        for( i = 0; YourWord[ i ]; i++) 
            YourWord[ i ] = tolower(YourWord[ i ] ); //Make uppercase letters the same as lowercase ones


        length = strlen(YourWord); // Calculate string length and store to variable length
        printf("\n Length of the string = %d characters\n",length); //Display the length of the string

        for(letters=33;letters<=126;letters++) //for loop to know the number of times a letter has occured
        {
            number=0;
            b=0;
            for(i=0;YourWord[i]!=0;i++)
            {
                if(letters==YourWord[i])
                {
                    number++;
                    b=1;
                }
            }
            if(b==1)

                printf("Number of times char %c occurred = %d time(s) and Percentage = %d%%"
                ,letters,number,number*100/length);
        }
        printf("\n Do you wish to try again continue (y/n) = \n"); //Check to see if the user wishes to go again.
        scanf("%e");
    }
    while('y' ||'Y');
    exit (0);
}


int main()
{
    BackGroundProgram();
}

The code seems to finish after the first go and does not give the user another chance.

I thought the do while loop meant that it would keep running the loop until the user says no
# 9  
Old 03-04-2012
Probably should have started this in a new thread as it's a bit different than your original question.

Anyway -- Your expression in the while needs to test the value of something. For instance, *x == 'y'. I didn't look very closely, but I also notice that your scanf() function doesn't provide a variable for the response which will likely cause unpredictable results if not a core dump.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Self extracting archive for Linux and windows

Is there a way to create a self extracting archive that works in both linux and windows? And if so how? Everything I have read on google only works in either Linux or Windows but not both. (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Creating loops inside a file and extracting and loading data

Help needed (1 Reply)
Discussion started by: Chand Shrestha
1 Replies

3. UNIX for Dummies Questions & Answers

Why is creating an RCS archive in /etc a "good thing"??

Hi guys, Why is creating an RCS archive in /etc a "good thing"?? (1 Reply)
Discussion started by: lemon_06
1 Replies

4. Shell Programming and Scripting

Extracting information and creating numeric values using awk

I have some variables containing for example m02-npt02-sr40-syn-dv0p01-16x12drw m02-npt02-sr40-syn-dv0p02-16x12drw m02-npt02-sr40-dv0p03-syn-16x12drw I want to extract the dv entry for example dv0p01 dv0p02 dv0p03 Then I want to convert to a numeric, the p specifies the... (5 Replies)
Discussion started by: kristinu
5 Replies

5. Shell Programming and Scripting

Extracting from archive | compressing to new archive

Hi there, I have one huge archive (it's a system image). I need sometime to create smaller archives with only one or two file from my big archive. So I'm looking for a command that extracts files from an archive and pipe them to another one. I tried the following : tar -xzOf oldarchive.tgz... (5 Replies)
Discussion started by: chebarbudo
5 Replies

6. Shell Programming and Scripting

Read specific file from a zip archive without extracting

Hi All, I would like to extract specific file from a zip archive. I have a zip archive "sample.zip". sample.zip contains few text files and images... text1.txt, text2.txt, pic.jpg etc... I need to read specific file "text2.txt" from "sample.zip" WITHOUT EXTRACTING the zip file. ... (4 Replies)
Discussion started by: sridharg
4 Replies

7. Shell Programming and Scripting

creating an RCS archive in /etc

Hi Why is creating an RCS archive in /etc a "good thing"? Hi Why is creating an RCS archive in /etc a "good thing"? (2 Replies)
Discussion started by: scofiled83
2 Replies

8. Solaris

problem in creating flash archive

Dear all I am in a problem. I have created a master server on which I have install a Solaris 10 OS as well as Oracle 10g with some additional solaris packages. Now I want to create a flash archive of this server and install that flash archive on another server, so that the new server will have... (6 Replies)
Discussion started by: girish.batra
6 Replies

9. UNIX for Dummies Questions & Answers

Extracting from a tar archive file

Can I extract files from an archive file (tar), where the filename includes the full directory path, to a different directory? For example the archive files may have a filename of /SrcFiles/XXX/filename.dat and I want to extract it to /SrcFiles/YYY/filename.dat. Since the archive file was... (1 Reply)
Discussion started by: nmalencia
1 Replies
Login or Register to Ask a Question