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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:19:00+00:00 2026-06-12T23:19:00+00:00

So I am entering an array and a number which is the length of

  • 0

So I am entering an array and a number which is the length of the array to a function called “Write” like this :

string write (int n, char t[100])

To keep it simple i would only like to write the values of the array out whit the help of this function like this:

{
    int i;

    for (i=1;i<=n;i++) {
        if (t[i]=='a') {
        printf("%c" , t[i]);
        }
    }

    return 0;
}

In the int main() only thing I did was I used a scanf for the n variable and gave from 1 to n a ‘a’ string value in the array.And I called the write function string write(n,t[100]); Here is the whole “main” :

    int main()  
{  
    int i,n;   
    char t[100];  
    scanf("%i" ,&n);  

    for (i=1;i<=n;i++) {
            t[i]='a';
            }
string write (n,t[100]);  
return 0;  
} 

My question is why wont this simple program run I can enter the value of the n but won’t print anything out? I must be missing something out whit the declaration’s or calling of the function I am new to C++.

  • 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-12T23:19:01+00:00Added an answer on June 12, 2026 at 11:19 pm

    string write(n, t[100]) is the prototype of your function (type omitted). If you want to call write, you need to do something like

    int main()  
    {  
        int i,n;   
        char t[100];  
        scanf("%i" ,&n);  
    
        for (i=1;i<=n;i++) {
                t[i]='a';
                }
    write(n,t);  
    return 0;  
    }
    

    Passing t[100] to your write function will give the 100th element of you string to your function, and that is not what you want to do. To pass the whole string, just use t.

    Another mistake is that you say write returns a string. But you return 0 in your code, you want to modify the write prototype to int write(int n, char t[100]);

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

Sidebar

Related Questions

I'm trying this code for entering values into multidimensional char array in C. The
From the selected answer in this SO-question this very ingenious function creates an Array
When entering a code line in Aptana Studio like <input id=send type=button value=Send onclick=calculate()
When entering 'https://apps.facebook.com/seemyfuture', Facebook automatically redirect users to Oauth dialog, while i didn't write
This site was working properly before I started encountering an error after entering some
HeyHo, I'm entering a name in the following website and submit this name with
Right, I have an array for floats which stores only 1s and 0s. I'm
I've seen pictures like this on Facebook: The instructions claim that your SIM card
I can't figure this out. I've create a simple class that returns an array
I am using the following function to search through an array recursively: function search2($array,

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.