• Register
0 votes
2.2k 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

Please log in or register to answer this question.

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 19 views
19 views
Problem: It&rsquo;s an urgent Problem, any help: Assign the size of userinput to stringsize. ex: if userinput = "hello", output is
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 3 views
3 views
Problem: I am trying to get an output of 5, but it is returning 0. I can't figure out what's wrong. The userInput "Hello" should have a size of 5 and userInput.size() should return 5.
asked Apr 25 ummeshani 10.8k points
0 votes
1 answer 6 views
6 views
Problem: Can anyone help me out about this? If yes, then please answer me.
asked Mar 27 niyatiry 3.9k points
0 votes
1 answer 609 views
609 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
1 vote
1 answer 9 views
9 views
Problem: How to read line by line using C++. Reading from a file c++.
asked Mar 24 PkGuy 23.5k points
0 votes
1 answer 14 views
14 views
Problem: For example, if data in an external text file is like this: 45.78 67.90 87 34.89 346 0.98 How can I read this text file and assign each number to a variable in c++? Using ifstream, I am able to open the text file and assign first number to a variable, but I don't know how to read the next number after the spaces.
asked Dec 27, 2020 Mashhoodch 13k points
0 votes
1 answer 24 views
24 views
Problem: How to Check state of inputFile after opening and each inputFile >> numbers[count] operation separately to make sure there is no errors in loading from the file. Also consider what should happen if the file contained less than ARRAY_SIZE numbers. I would also suggest using std::array or std::vector which perform more checks in good debuggers.
asked Dec 22, 2020 Mashhoodch 13k points
2 votes
1 answer 298 views
298 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, 2020 morrisBson 3.2k points
0 votes
1 answer 3 views
3 views
Problem: In Visual Studio 2010 (Ultimate), is it possible to step through some code, and, if a variable is not correct (e.g. you want to get all records beginning with 'A' but there is none, so you want to try 'B' instead), is it possible to change the code while ... have to stop debugging, change a value, then debug again and see the result. It'd be much easier to do it all in debug mode, anyway.
asked Apr 26 sumaiya simi 43.9k points