我正在尝试将初始化的char指针数组传递给函数.我似乎无法弄清楚为什么函数只会打印出数组中每个元素的数字.
有谁知道如何从传入的指针数组中打印每个字符串元素?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
void sort(char *);
int main()
{
char *states[4] = {"Florida", "Oregon", "California", "Georgia"};
sort(*states);
return 0;
}
void sort(char *states)
{
int x;
for (x = 0; x < 4; x++) {
printf("\nState: %d\n", states[x]); //only this will compile
//printf("\nState: %s\n", states[x]); //need to print this.
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的函数中执行以下操作,但不断收到分段错误错误.当我尝试[iModify - 1]用作索引时,它失败了.
你能不能将int变量计算用作C中的索引?
int modify(pb *PhoneBook)
{
int x;
int iModify = 0;
char name_num[] = {'\0'};
print(PhoneBook);
printf("\nWhich entry would you like to modify? ");
scanf("%d", &iModify);
printf("\niModify - 1: %d\n", iModify - 1);
printf("\nModify name or number? ");
scanf("%s", name_num);
convert_u(name_num);
if (strcmp(name_num, "NAME") == 0) {
printf("\nEnter new name: ");
scanf("%s %s", PhoneBook[iModify - 1].cFirstName, PhoneBook[iModify - 1].cLastName); //fails here
}
else if (strcmp(name_num, "NUMBER") == 0) {
printf("\nEnter new number: ");
scanf("%s", PhoneBook[iModify …Run Code Online (Sandbox Code Playgroud) I'm trying to do a version number update on files in CVS.
My initial logic was to update a float (1.1 --> 1.2 --> 1.3) which worked fine until I get to 1.9, then it updates to 2.0.
I'm trying to update to 1.10 with this logic, but it's throwing an error when I try to increment the x in 1.x (ver[1] += 1).
def replace_string():
with open(filename) as f:
found = False
#for line in fileinput.input(filename, inplace=1):
for line …Run Code Online (Sandbox Code Playgroud)