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 7923771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:25:25+00:00 2026-06-03T17:25:25+00:00

I have been struggling to understand some pieces of this code. It asks to

  • 0

I have been struggling to understand some pieces of this code. It asks to enter some strings, will count the vowels and display the result. It is some definitions that I don’t understand, the mechanics I do.

In the definitions inside main(). I dont understand what for an argument this ‘(cad)’ is in the entrada function. One line above it is defined an array of 3 pointers to char, namely char *cad[N] if I correctly believe. I would say my problem is everything in the Main function, how the arguments make sense inside the parentheses for the functions. After that I understand alright.

# include<stdio.h>
# include<stdlib.h>
# include<string.h>
# include<ctype.h>
# define N 3


// Function Prototypes

void salida(char *[], int*);
void entrada(char *[]);
int vocales(char *);

int main ()
{
    char *cad[N];  // declaring an array of 3 pointers to char
    int j, voc[N]; // declaring ints and an array of ints
    entrada (cad);// Function to read in strings of characters. 
    // count how many vowels per line
    for (j = 0; j<N; j++)
    voc[j] = vocales(cad[j]); // it gets the string and sends it to function vocales to count how many vowels. Returns number to array voc[j]
    salida (cad, voc);
}

// Function to read N characters of a string
void entrada(char *cd[] ){
    char B[121]; // it just creates an array long enough to hold a line of text
    int j, tam;

    printf("Enter %d strings of text\n", N );

    for (j= 0; j < N; j++){
        printf ("Cadena[%d]:", j + 1);
        gets(B);
        tam = (strlen(B)+1)* sizeof(char); // it counts the number of characters in one line
        cd[j] = (char *)malloc (tam); // it allocates dynamically for every line and array index enough space to accommodate that line
        strcpy(cd[j], B); // copies the line entered into the array having above previously reserved enough space for that array index
    } // so here it has created 3 inputs for each array index and has filled them with the string. Next will be to get the vowels out of it

}

// Now counting the number of vowels in a line
int vocales(char *c){
    int k, j;

    for(j= k= 0; j<strlen(c); j++)
        switch (tolower (*(c+j)))
        {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
              k++;
              break;
        }
    return k;
}

// function to print the number of vowels that each line has
void salida(char *cd[], int *v)
{
    int j;

    puts ("\n\t Displaying strings together with the number of characters");
    for (j = 0; j < N; j++)
    {
        printf("Cadena[%d]: %s has %d vowels \n", j+1, cd[j], v[j]);
    }
}
  • 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-06-03T17:25:27+00:00Added an answer on June 3, 2026 at 5:25 pm

    cad is an array of pointers. It only has space for N pointers, not the actual string data. The entrada function reads N strings of text. For each of these it allocates some space with malloc and copies the string there. entrada sets the corresponding pointer in cad (which it sees as cd) to point to the allocated buffer.

    When you pass an array as an argument, you are not passing a copy. Instead, the address of the first element is passed to the function. This is how entrada can modify the pointers in cad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for quite some time having been accustomed to
I have been struggling with this for a while now. given a set of
I have been struggling with Core Data sigh so I decided to work this
I have been struggling with this error for more than two hours: error: aggregate
I have been struggling to think of some decent uses for things like vectors
I have been struggling with this question for awhile now, and I haven't reached
I'm unfamiliar with Javascript and have been struggling to understand how I'd go about
I've been struggling for this for an hour and I don't understand why there's
So, for the past few days I have been struggling to understand how to
I have been struggling with this for a while and just can't work it

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.