0

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#define size 5


void *displayName(void *received_array){ 


char *name = received_array;


for(int i=0;i<5;i++)

     puts(name[i]);


 pthread_exit(0);

 }
 
int main(){
 pthread_t threadid1;

char name[10][50];
strcpy(name[2], "raj");
strcpy(name[3], "pol");
strcpy(name[4], "sara");*/

pthread_create(&threadid1,NULL,displayName, name);

}


In function ‘displayName’: q2v2.c:42:15: warning: passing argument 1 of ‘puts’ makes pointer from integer without a cast [-Wint-conversion] 42 | puts(name[i]); | ~~~~^~~ | | | char

2 Answers 2

0

You should match the type of passed pointers.

Replace

char *name = received_array;

with

char (*name)[50] = received_array;

Also don't forget to initialize name[0] and name[1] in the main() function.

Sign up to request clarification or add additional context in comments.

Comments

0
<source>:9:15: warning: passing argument 1 of 'puts' makes pointer from integer without a cast [-Wint-conversion]
    9 |      puts(name[i]);
      |           ~~~~^~~
      |               |
      |               char

This warning means that puts expect a pointer but you gave it an integer type, such as a char rather than a char*.

If you still don't understand the warning after reading the text, the compiler is kind enough to point out the exact location of the bug with "ASCII art":

    9 |      puts(name[i]);
      |           ~~~~^~~
      |               |
      |               BUG HERE this is a char

When the compiler points out the exact location of the bug, it's advisable to suspect that the compiler is right and this is indeed the exact location of the bug.

That being said, you pass on a char(*)[50] to the pthread then use it as a char* inside the thread callback, which is a second bug.

1 Comment

Overall, this is really basic stuff and if you can't resolve these kind of bugs on your own, then you should step back to studying arrays, pointers and strings before doing semi-advanced stuff like multi-threading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.