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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:16:02+00:00 2026-06-06T16:16:02+00:00

Suppose that in the main I have a function a : a(c); and c

  • 0

Suppose that in the main I have a function a:

a(c);

and c is declared like

char* c.

The function a is actually like this:

void a(char* v)
{
    v[0] = 1;
    v[1] = 2;
}

Is this wrong? Because the program is saying that c is uninitialized in this function.

EDIT:
More code:

byte* msg;

insere_msg(t_msg, argv[2], msg);

void insere_msg(int size, char name[MAX], byte* v)
{
    FILE *fp;
    int i = 10;
    int n = 0;
    char aux;

    v[0] = (byte) 4;
    v[1] = (byte) 8;
    v[2] = (byte) 15;
    v[3] = (byte) 16;
    v[4] = (byte) 23;
    v[5] = (byte) 42;
    v[6] = (byte) size>>(3*8);
    v[7] = (byte) size>>(2*8);
    v[8] = (byte) size>>(1*8);
    v[9] = (byte) size;

    fp = fopen(name, "r");

    while(n < size)
    {
        fscanf(fp, "%c", &aux);
        v[i] = (byte) aux;
        i++;
        n++;
    }
}
  • 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-06T16:16:04+00:00Added an answer on June 6, 2026 at 4:16 pm

    looking at your edit:
    You will need to allocate the memory using the malloc command somewhere.

    msg = (char *)malloc(sizeof(char) * atLeastThree);
    

    Now that msg is allocated, it can be pushed into your insere_msg function and your a function.

    You should also implement this more “safe” code:

    void a(char * v, unsigned int sizeofV){
        if(NULL != v && sizeofV >= 3){
            v[0] = 1;
            v[2] = 2;
        }else{
            printf("array v is either not allocated or not of proper size");
        }
    }
    

    you really SHOULD check to make sure that a point type has been initialized and that it is valid for the purpose of the function you are trying to pursue, before you manipulate the data being pointed to by the pointer!!!

    NOW, this will not SOLVE the problem if you have not allocated the memory, it will simply keep it from erring out.

    If you want to have EVEN SAFER code, you will pass in the unallocated pointer, and the let the function allocate and return the size. The only thing here is, that the caller if responsible for deallocating the memory.

    unsigned int a(char * v){
    
        v = (char *)malloc(sizeof(char) * Necessity);
    
        if(NULL != v){
            v[0] = 1;
            v[2] = 2;
        }else{
            printf("array v is either not allocated or not of proper size");
        }
    
        return Necessity;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts
Suppose i have one simple function in my program. Whenever i call that function
Suppose I have some code like this: class Visitor { public: Visitor(callBackFunction) {} void
Suppose I have an element called #container-main . How do I make that display:none
Suppose that you have a function f: List a -> a such that f
suppose that you have two activities A(which is the main activity) and B when
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
Suppose I have a function that does something on an arbitrary container type (C++11):
Suppose i have a main js file on the website that contains some code

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.