c - Passing an Array pointer and printing -


despite efforts resolve problem, whenever compile code either has errors or fails immediately. goal create array of characters in 'run_program' function, , pass array (as pointer can instantly return changes) my_str_n_cat function. unfortunately suck @ coding can't print. appreciated.

//task #1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ char my_str_n_cat (char *source_ptr) {     (*source_ptr);     printf("my name %s", *source_ptr);  }  //main ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int run_program () {     int ;     char source[6] = {'d', 'i', 'l', 'l', 'o', 'n'}, destination[10];     char *source_ptr, *destination_ptr;      source_ptr = source;      my_str_n_cat(&source_ptr); } 

there more 1 problem,

  1. this definition,

    char source[6] = {'d', 'i', 'l', 'l', 'o', 'n'} 

    cannot printed printf() tried.

    the printf() function, "%s" specifier expects pointer string parameter, yours not string strictly speaking.

    for string, needs terminating nul byte, '\0', correct

    char source[7] = {'d', 'i', 'l', 'l', 'o', 'n', '\0'} 
  2. you dereference pointer when pass printf(), shouldn't, remove * before source_ptr.

  3. you passing address of array, , don't need because array name equivalent pointer first element of array, this

    my_str_n_cat(source_ptr); 

    would sufficient.

    the main difference here type of pointer, gives compiler information used when pointer arithmetic or when dereference pointer through subscript operator, same.

    in case nothing speciall happen, because poitner being converted correct pointer type.

    this 1 of things indicates did not enable compiler warnings.

the fact don't there warnings compiler, means didn't enable them, should let compiler find mistakes common, that's why compiler have diagnosis features, , can enable them giving switches compiler command.