我想返回一个句子,一个单词全部以大写形式返回。我有点知道我想如何处理整个事情,但我就是无法让它发挥作用。这是我到目前为止的代码,但需要更多的工作。
我现在很迷茫的任何想法
这就是问题的措辞。
/*
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(char sz[], char 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') */