字符串库函数 [英] String library functions

查看:107
本文介绍了字符串库函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将userInput的大小分配给stringSize。例如:如果userInput =Hello,则输出为:

userInput的大小:5





< pre lang =c ++> #include < < span class =code-leadattribute> stdio.h >
#include < string.h < span class =code-keyword>>

int main( void ){
char userInput [ 50 ] = < span class =code-string> ;
int stringSize = 0 ;

strcpy(userInput, Hello);

/ * 您的解决方案在这里* /




printf( 尺寸userInput:%d \ n,stringSize);

return 0 ;
}





我的尝试:



试过:



  #include   <   stdio.h  >  
#include < string.h >

int main( void ){
char userInput [ 50 ] = ;
int stringSize = 0 ;

strcpy(userInput, Hello);

/ * 您的解决方案在这里* /

strlen(userInput)+1;


printf( userInput的大小:%d \ n,stringSize);

return 0 ;
}

解决方案

第一条规则:当您寻求帮助时,请说出问题或疑问。



从我看到的,你所做的并不是那么糟糕,但你错过了基础知识,检查你的课程。



建议:学习使用调试器,它会让你看到你的代码在做什么,相信我,它有助于理解什么是错误。



-----

如果你不明白你的代码在做什么或为什么它做了什么,答案是调试器。 br />
使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里显示你的代码正在做什么,你的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。如果代码没有达到预期的效果,那么您就接近了一个错误。


 #include< stdio.h> 
#include< string.h>

int main(void){
char userInput [50] =;
int stringSize = 0;

strcpy(userInput,Hello);

stringSize = strlen(userInput);

printf(userInput的大小:%d \ n,stringSize);

返回0;
}


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 userInput[50] = "";
   int stringSize = 0;

   strcpy(userInput, "Hello");

   /* Your solution goes here  */
  
  
 

   printf("Size of userInput: %d\n", stringSize);

   return 0;
}



What I have tried:

Tried:

#include <stdio.h>
#include <string.h>

int main(void) {
   char userInput[50] = "";
   int stringSize = 0;

   strcpy(userInput, "Hello");

   /* Your solution goes here  */
  
   strlen(userInput)+1;
 

   printf("Size of userInput: %d\n", stringSize);

   return 0;
}

解决方案

First rule: when you ask for help, state a question or a problem.

From what I see, what you have done is not so bad, but you are missing the very basics, check your lessons.

Advice: Learn to use a debugger, it will allow you to see what is doing your code, believe me, it help to understand what is wrong.

-----
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


#include <stdio.h>
#include <string.h>

int main(void) {
   char userInput[50] = "";
   int stringSize = 0;

   strcpy(userInput, "Hello");

   stringSize = strlen(userInput);
   
   printf("Size of userInput: %d\n", stringSize);

   return 0;
}


这篇关于字符串库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆