Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6983677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:27:01+00:00 2026-05-27T18:27:01+00:00

As a learning exercise, I am creating a program that converts characters entered through

  • 0

As a learning exercise, I am creating a program that converts characters entered through argv[1] to integers. The program then finds the digital mean of the integers.

For example: abc would be 123, and 1+2+3 = 6, six being the digital mean. The first part of the program works, but I am unable to properly code the portion that finds the digital mean.

Output from word abc should be 123 6; instead it is 123 150.


EDIT: Solved!

#include <stdio.h>
#include <strings.h>

int main(int argc, char *argv[])
{
    char stra[27], strb[0];
    int str_num, str_len;
    int final = 0;

    if (argv[1][0] < 'a')
    {
        printf("!Argument missing!");
        return 0;
    }

    strcpy(stra, argv[1]);
    str_len = strlen(stra);

    for (str_num = 0; str_num < str_len; str_num++)
    {
        if (stra[str_num] <= 'z' && stra[str_num] >= 'a')
        {
            strb[str_num] = (stra[str_num] - 'a' + 1) % 9 + '0';
            if (strb[str_num] == '0')
            {
                strb[str_num] = '9';
            }
        }
        else
        {
            printf("%s !Please use only the lower case!", stra);
            return 0;
        }
    }

    for (str_num = 0; str_num < str_len; str_num++)
    {
        final += strb[str_num] - '0';
    }

    printf("%s %i", strb, final);
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:27:02+00:00Added an answer on May 27, 2026 at 6:27 pm
    #include <stdio.h>
    #include <strings.h>
    int main(int argc, char *argv[])
    {
        char *stra;
        char *strb;
        int str_num;
        int str_len;
        int final;
        final = 0;
        if ( (argc >= 2 && argv[1][0] < 'a') || (argc <= 1))
        {
            printf("!Argument missing!");
            return 0;
        }
        str_len = strlen(argv[1]);
    
        strb = (char*) malloc((str_len+1)*sizeof(char));
    
        for (str_num = 0; str_num < str_len; str_num++)
        {
            if (argv[1][str_num] <= 'z' && argv[1][str_num] >= 'a')
        {
            strb[str_num] = (argv[1][str_num] - 'a'+1) % 9 + '0'; //to get string with numbers from 1 to 9
            }
            else
            {
                printf("%s !Please use only the lower case!",argv[1]);
                return 0;
            }
        }
        strb[str_len] = '\0' // put the end char of the string : mandatory to print it.
        for (str_num = 0; str_num < str_len; str_num++)
        {
            final += strb[str_num] - '0';  // count the sum of the numbers from 1 to 9 ?
        }
        printf("%s %i",strb,final);
        free(strb);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a blog engine as a learning exercise and one particular problem has
I'm designing an application that supports plugin development. Its more of a learning exercise.
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
I'm new to Corona and as a learning exercise I'm creating a simple game
I am working on a POSIX C learning exercise that involves recursively listing files/folders
I've been trying to do something as a learning exercise that I thought should
As a learning exercise, I'm writing a Python program to connect to a channel
query level: beginner As part of a learning exercise I have written code that
As a learning exercise I'm building a basic scientific computation environment based on .NET.
I am writing a huffman implementation in Python as a learning exercise. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.