从在C的char *获取单个字符 [英] Get a single character from a char* in C

查看:710
本文介绍了从在C的char *获取单个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过字符来遍历字符或c提取的char *单个字符?

考虑以下code。现在,这是获得单个字符的最佳方式?
我建议不使用任何字符串函数的方法。

 的char * A =STRING;


解决方案

另一种方式:

 的char *我;对于(I = A; *我;我++){
   // i指向依次为[0],A [1],...,直到观察'\\ 0'。
}

Is there a way to traverse character by character or extract a single character from char* in C?

Consider the following code. Now which is the best way to get individual characters? Suggest me a method without using any string functions.

char *a = "STRING";

解决方案

Another way:

char * i;

for (i=a; *i; i++) {
   // i points successively to a[0], a[1], ... until a '\0' is observed.
}

这篇关于从在C的char *获取单个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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