• Register
0 votes
1.4k views

Problems :

Assign the size of userInput to stringSize. Ex: if userInput = "Hello", output is:
Size of userInput: 5

#include <stdio.h>
#include <string.h>
int main(void) {
   char userInputArray[50] = "";
   int stringInputSize = 0;
 strcpy(userInputArray, "Hello");
 /* Your solution starts here  */
  
printf("Size of userInputArray: %d\n", stringInputSize);
   return 0;
}
6 5 3
7,540 points

1 Answer

0 votes

Solution :

Please learn to use the Debugger, it will help you to see that what your code is doing, believe in me, it will help you to understand what is wrong.

When you don’t know what your code should be doing or why the does what it does, the answer to this is Debugger.
You can use the debugger to see what your code is actually doing. You need to just set a breakpoint and see how your code is performing, the debugger allows you to execute the lines 1 by 1 and to inspect the variables as it executes it, it is an incredible learning tool.
The debugger is always here to show you what your code is doing and your task is to compare it with what it should be doing.

Code solution as below :
 

#include <stdio.h>
#include <string.h>
int main(void) {
   char userInputArray[50] = "";
   int stringInputSize = 0;
   strcpy(userInputArray, "Hello");
   stringInputSize = strlen(userInputArray);
   
printf("Size of userInputArray: %d\n", stringInputSize);
   return 0;
}
9 7 4
38,600 points

Related questions

0 votes
1 answer 229 views
229 views
Problem : I am completely stuck on this problem Given an array of ints, return True if the array contains a 2 next to a 2 somewhere. has22([1, 2, 2]) → True has22([1, 2, 1, 2]) → False has22([2, 1, 2]) → False I know the basic idea but I am unable to implement it. ... this, eg. graph, search? def has22(mynums): for l in mynums: if ( (mynums[l] = 2) and (mynums[l+1] = 2) ) return True return False
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 43 views
43 views
Problem: I am wondering how can I determine the size of the array in some of the cases. I have written the below small sample program to illustrate what I am trying to say. int main(int argc, char *argv[]) {     std::vector<unsigned char>v;     unsigned char p[1024 ... return 0; } So I want to know the some or the other way to tell a vector how many elements it currently is supposed to be holding.
asked Jul 21 Raphael Pacheco 4.9k points
0 votes
1 answer 88 views
88 views
Problem : Need solution for bellow problem statement print the data members of inventorytag. ex: if item_id is 314 and quantity_remaining is 500, print:
asked Nov 7, 2019 peterlaw 6.9k points
2 votes
1 answer 93 views
93 views
Problem : I am currently learning to use the windbg to debug the crash dump. I am facing following error. What is the meaning of &ldquo;first/second chance not available&rdquo; ? This dump file has an exception of interest stored in it. The stored exception information ... via .ecxr. (e38.2270): Access violation - code c0000005 (first/second chance not available) How can I fix above error?
asked Mar 25 morrisBson 3.2k points