• Register
0 votes
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 450 views
450 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 120 views
120 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 8 views
8 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 9.1k points
0 votes
1 answer 12 views
12 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 9.1k points
2 votes
1 answer 214 views
214 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 98 views
98 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
0 votes
1 answer 5 views
5 views
Problem: synchronous xmlhttprequest on the main thread is deprecated
asked Feb 17 Dan phillip 1.9k points
0 votes
1 answer 549 views
549 views
Problem : I have just downloaded Python and Visual Studio & trying to test the debugging feature for a simple "Hello World" script but I'm receiving this error: failed to launch the python process, please validate the path 'python' Could someone please tell me how to fix this?
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 14 views
14 views
I know it sounds weird but I wanted to know if there is a possibility in C ++ to write the addresses that a dynamic array saves to a file so that you can read the file and use the saved addresses with other pointers. What would be the way to enter and remove the addresses of the file?
asked Aug 14, 2020 game 4.6k points