Question

Can someone explain to me why buff doesn't have the data that i put inside of the char pointer name "data"

29 int main) 30 putsCHello World; int yes 2; int finally -1; char *buff; int ret = 0; char *hh buff malloc(7) printf(buff %p \n, &buff); ret = puff(yes, buff, finally) ; 32 36 37 39 40 41 42 . 43 putsC putsCbuff; for(int i-0; i < 6; i++) printf(%C·buff[i]); putsCdone); 45 46 47 return 0 input Hello World buff 0x7fff79b83f08 data 0x7fff79b83ec8 data 20x7fff79b83ec8 c dej a z data cdej a z buff done

0 0
Add a comment Improve this question Transcribed image text
Answer #1

There are certain errors with the code, first is line 37 where pointer conversion is not done right, you need to use the pointer conversion i.e. buffer=(char *)malloc(7); and also use an exception in case the memory is not allocated i.e. if(buffer!=NULL)  

Moreover, I couldn't understand the the use of function puff, where parameter y is never used.

Take care of these errors and the code shall work fine.

Regards

Add a comment
Know the answer?
Add Answer to:
Can someone explain to me why buff doesn't have the data that i put inside of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • These are my instructions: Your data should have been read in from the data file and stored into ...

    These are my instructions: Your data should have been read in from the data file and stored into an array. Next you need to calculate the following and display in a single Message box: Average score Highest score Lowest score Mode of the scores Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes. This is the .text file to use with the instructions: 20 21 22...

  • Can someone tell me why this is not printing in the screen. I know i commented...

    Can someone tell me why this is not printing in the screen. I know i commented out the first couple functions but the last one is not working. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 5 #define COLS 5 #define FREE 2 #define SCALE 15 #define SHIFT 1 #define MAXVAL 75 #define FALSE 0 #define TRUE 1 void welcomeScreen(); void clearScreen(); void displayExplicitCard(); void displayCard(); void displayRandomCard(); void fillCardRand(); void setValue(); void displayBingoCard(); void initializeArrays (); int main...

  • what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n");...

    what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n"); for ( 2 { total = i + j; printf("%d", total); بہا } getchar(); return 0; } Find the for loop content | Output of progrm 5 15 1 11 21 31 41 51 61 2 12 22 32 25 3 13 23 33 43 53 63 4 14 24 34 44 54 64 35 45 6 16 26 36 46 56 66 7...

  • I literally have no idea what I’m doing. Help!!! Please show work!! Write an essay using...

    I literally have no idea what I’m doing. Help!!! Please show work!! Write an essay using Word and post it as an attachment to the discussion. Cover the following points. Choose a data set from Stat Disk using one of the following files from 13th Edition Elementary Statistics: Oscar Winner Freshman 15 Word Count Garbage Weights Passive and Active Smoke If the file contains more than one variable, choose a quantitative variable. Create a histogram using your chosen variable and...

  • 11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single...

    11.9 Week 11 Lab: 2D Arrays For this lab, you only need to write a single user-defined function that analyzes a 2D array of chars. You do NOT need to write any of the code in main0 that calls your function. Make sure to use the template and only add code to the user-defined function. Write a function win0 with the following definition (i.e. prototype): int win(char board17)15), char player) The function win0 should return a 1 if the character...

  • Part 3.  Write a program to dynamically allocate some char buffers, use memset to fill them, and...

    Part 3.  Write a program to dynamically allocate some char buffers, use memset to fill them, and use memcpy and memmove to move the data around. I suggest you do part 3a, test and verify it’s working as expected, then add part b, test & verify, then do part 3c.  You only need to turn in the complete program, but doing it in steps will help both with understanding and if you have bugs along the way. Part 3a. a.Allocate 2 char...

  • Can someone please explain the integration rules for "e," especially while solving them? I'm obviously missing...

    Can someone please explain the integration rules for "e," especially while solving them? I'm obviously missing something... Please answer 16, 18, 20, and 41 (WITH EXPLANATIONS, PLEASE!!!) Thank you!! (2x + 4)(x² + 4x - 8)'dx sro 35. f(x) = 2x + 37. f(x) = 2x2 39. f(x) = x? + 40. f(x) = x?: 1 42. f(x) = x(x + 1) dx + 3x) dx 44. f(x) = + 14. xe" da 10. 11. 12. 13. I dx Hint:...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study...

    c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT