我的目標是使用簡單的 for 回圈列印出字串的前 N ??個字符(len變數)。但是,代碼似乎不起作用。例如,對于輸入printFrstChars("Example",3),代碼應該列印出來Exa,但它不會列印出任何東西。
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void printFrstChars (char inp[], int len)
{
for(int i = 0; inp[i] != '\0' && i <= len; i ){
printf("%s", inp[i]);
}
}
int main ()
{
int len = 0;
char inp[100];
printf("Input string and length:\n");
scanf("
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/333177.html
