-1
我想返回一個句子,一個單詞全部以大寫形式返回。 我知道我想怎樣去做所有的事情,但我無法完成它的工作。 這是迄今爲止的代碼,但需要更多的工作。使字符串中的一個單詞出現在大寫,C編程
任何想法我現在很失落
這就是問題的措辭。
/*
strhlt - Highlight substring
Author - Your Name
Limitations: The function will search for and highlight (capitalize) one instance
of the szHigh string. It will not highlight a possible
2nd instance
Hint: Perhaps the function strindex from K&R can be utilized
to solve part of the problem?
In/Out: sz - source string to be highlighted 'in place'
In: szHigh - string to search for and highlight
return: - Returns 0 (false) if szHigh is not found in sz, otherwise -1 (true)
Sample:
char szTxt[] = "These are the best of times";
i = strhlt(szTxt, "best");
will return -1 (true) and the text in szText has changed to
"These are the BEST of times"
*/
INT strhlt(燒焦SZ [],炭szHigh []);
#include <stdio.h>
#include <conio.h>
#include <string.h>
#pragma warning(disable : 4996)
/* getline: get line into s, return length */
int getline (char s[], int lim)
{
int c, i;
i = 0;
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* getline: get line into s, return length */
int getline (char s[], int lim)
{
int c, i;
i = 0;
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* strindex: return index of t in s , -1 if none */
int strindex (char s[], char t[])
{
int i, j, k;
for (i=0; s[i] != '\0'; i++){
for (j=i, k=0; t[k] != '\0' && s [j]==t[k]; j++, k++)
;
if (k > 0 && t[k] == '\0')
return i;
}
return -1;
}
// int strhlt(char sz[], char szHigh[]); //
main()
{
char sz [60];
strcpy
getline (sz,60);
getline (sz, 60);
strhlt (sz, something);
getline();
printf("Please enter short phrase (60 chars max): ");
printf("\n\nPlease enter a word to highlight (10 chars max): %s", sz);
getchar();
return 0;
}
/* (sz >= 'A' && sz >= 'Z' || sz >= 'a' && sz >= 'z') */
爲什麼兩次'getline'? – haccks
_「不能完全得到它的工作」_是必要的,但沒有足夠的條件對SO帖子 – P0W
如何多一點信息?這看起來像是一個家庭作業問題,如果你能用文字描述你想做什麼,我們可以幫助你到達那裏。 – plinth