[英](For beginners): Input Array of Characters w/ no specific size. Use of: Array of Characters. Create a condition that implements an interval. (in C)
1)有人可以显示如何输入字符数组吗,只要用户键入字符,就可以使该数组成为可能。 (喜欢一步一步,对于初学者来说超级复杂,并解释您使用的功能)<3 <3
2)然后如何在函数中使用该字符数组,循环或在某个索引处打印该字符串的字符。
3)还可以请某人演示如何处理循环中具有以下间隔的条件,例如:
变量<[65-90] <----您将如何在代码中正式键入它
4)关于改进功能的任何建议?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int giveInitials(void)
{
char name[], upperCasedName[];
name = fgets("Full Name: ");
uppperCasedName = toupper(name);
int n, count, i;
n = strlen(name);
count = 0;
i = count;
while (count < n)
{
// While Loop1: iterates until (int) value at index of char array (upperCasedName) = 65-90 (until it gets to the first letter)
while ((int)upperCasedName[count] != [65-90] )
{
for (i = count; i < n ; i++)
{
count++;
}
}
printf("%c", upperCasedName[count]);
// While Loop2: iterates until (int) value at index of char array (upperCasedName) != 65-90 (until it gets to a none-letter)
while ((int)upperCasedName[count] = [65-90])
{
for (i = count; i < n; i++)
{
count++;
}
}
} // End of While loop
}
首先,尝试首先阅读基本的ansi C书籍,这些都是基本知识。 您的示例代码看起来真的很奇怪。 C没有“字符串”,只是数组,也就是说,如果您的目标是获取首字母,则将使用类似以下的代码来实现。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, char * argv[])
{
char c;
char initials[1];
int flag1=0;
int counter=0;
while ( (c=getchar()) != EOF )
{
if (counter==0){
initials[0]=c;
printf ("\nFirst char is %c\n", c);
}
if (flag1==1){initials[1]=c;break;}
if ( c == ' ')
{
flag1=1;
}
counter++;
}
printf ("\nInitials: %s\n", initials);
}
如果数组是array [100],则可以通过使用内部的Int变量作为array [a]来遍历数组,其中a为'Int a = 0 ;,然后在函数(a ++)中增加a或指向a比方说,特定位置array [50]。
变量<[65-90]:如果一段时间使用,您可以进行如下操作。
而(a> = 65 && a <= 90){这里有一些代码}
仅当a在您的范围内时,这将限制操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.