字符串数组

#include <stdio.h>
#include <string.h>
main()
{
char str[10]={‘h‘,‘e‘,‘\0‘,‘l‘,‘l‘,‘o‘};//"hello"
printf("string length: %ld,and string is %s\n",strlen(str),str);

for(i=0;i<11;i++)
{
printf("[index:%d]%c\n",i,str[i]);
}
}

时间: 2024-08-03 20:04:18

字符串数组的相关文章

字符串数组中两个字符的最短距离

[leetcode] https://leetcode.com/problems/shortest-word-distance/ For example,Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Given word1 = "coding", word2 = "practic

Java求字符串数组交集 并集 差集 去重复并集

//系统方法 package com; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Test { public static void main(String[] args) { List list1 =new ArrayList(); list1.add("1111"); list1.add("2222"); list1.add

关于清空字符串数组

嗯,由于要多次输出某字符串数组,比如str[100], 所以,每次输出完之后需要对其进行重置╮( ̄▽ ̄)╭ 可以使用如下的函数: menset(str, 0, 100); 嗯,一共三个参数,很容易看明白哇 <( ̄︶ ̄)/ 度娘上是这么评价的: memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法!╰( ̄▽ ̄)╯

利用快慢下标操作字符串数组

1.去除掉多余的空格: e.g. Before:   Life___is__short___I___use___python_'\0'(下划线为空格) After:  Life_is_short_I_use_python'\0' (去除掉多余的空格) 去掉空格比较简单,我们可以通过逐个判断字符,如果有连续的空格就使数组左移直到只剩一个空格,可是这么做效率十分低下; 前面学习过利用快慢下标的方法实现快排思想,这里也可以采用类似的方法 : 对于删除后的数组,长度将减少或者不变,则指向删除后数组的下标

Android中资源文件中的字符串数组string-array简单用法

在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例子如下: 把相应的数据放到values文件夹的strings.xml文件里,或是其他自定义的xml中都可以,以下操作方法相同. <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="sports"> <item>足球<

本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并打印输出。

/** * Homework14 * * @Description:本程序找出字符串数组 String[] arr = {"welcome", "china", "hi", * "congratulation", "great"} 中的长度最大的元素,并打印输出. * StringDemo01 * * @author  * * email: [email protected] 2017年4月18日下午6:3

iOS开发入门 ? C语言(字符串、字符串数组、命令行参数)

字符串 1. 概念 用双引号引起来的就是字符串 "a string" //C语言编译器会将两个并列的字符串自动拼接成一个字符串 "a string""another a string" // \是换行连接的标记(一行不够写) "a looooooooooong \ string" 常见ASCII编码: 'A' == 65    'a' == 97    '0' == 48    '\0' == 0 int a[10]; //表

利用char, str2mat, strvcat创建多行字符串数组

用专门函数char , str2mat , strvcat创建多行字符串数组示例. 1.char('str1', 'str2',...) Convert to character array (string)转换成字符串数组,空字符串是有效的. 示例:S1=char('This string array','', 'has two rows.')   S1 = This string array has two rows. 2.str2mat  (新版本中被char替代) Form blank-

Substring with Concatenation of All Words, 返回字符串中包含字符串数组所有字符串元素连接而成的字串的位置

问题描述:给定一个字符数组words,和字符串s,返回字符数组中所有字符元素组成的子串在字符串中的位置,要求所有的字符串数组里的元素只在字符串s中存在一次. 算法分析:这道题和strStr很类似.只不过strStr是子串,而这个题是字符串数组里的元素组成的子串,字符串数组里的元素是无序的,但是必须全部包含.所有考虑使用map集合.关键点在于几个临界值,字符串元素在s中重复了怎么做,找到一个符合的子串后怎么做,有字符串元素不匹配怎做. import java.util.ArrayList; imp

C 入门 第五节 多维数组 字符串数组

#pragma mark  ----------二维数组----------int main(int argc, const char * argv[]) {/*    1 . 二维数组的本质:将数组作为数组元素的数组,称为数组的数组    2 . 类如:管理一个班4个学生的年龄,将一维数组作为数组元素,存储到另一个数组中    int age[4] = {12,13,14,15};    12,13,14,15    21,22,23,24    31,32,33,34    3 . 为了形象