I'm trying to print "and" line using fgets.
I'm having trouble using toupper c macro in strindex
- use fgets()
- define macro TOUPPER(c)
- use define macro in strindex ()
- only use printf, fgets, fopen
- print out line that has "and"
so far my code is
#define _CRT_SECURE_NO_WARNINGS
#define TOUPPER(c) (c >= 'A' && c <= 'Z')
#include <stdio.h>
#define MAXLINE 1000
int main() {
FILE* f = fopen("poem.txt", "r");
char line[MAXLINE];
while (fgets(line, MAXLINE, f) != NULL) {
if (strindex(line, "and") >= 0)
printf("%s", line);
fclose(f);
return 0;
}
int strindex(char s[], char t[])
{
int i, j, k;
for (i = 0; s[i] != '\0'; i++) { //search the array and keeps our place!
for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++)
//j searches where we are starting with i in s, k searches t
; //search for a match!!!
if (k > 0 && t[k] == '\0') //if we found a match
return i;
}
return -1;
}
txt file is
The Flea - John Donne
Mark but this flea, and mark in this,
How little that which thou deniest me is; It sucked me first, and now sucks thee, And in this flea our two bloods mingled be; Thou know'st that this cannot be said A sin, nor shame, nor loss of maidenhead, Yet this enjoys before it woo, And pampered swells with one blood made of two, And this, alas, is more than we would do.
Oh stay, three lives in one flea spare, Where we almost, nay more than married are.
This flea is you and I, and this Our marriage bed, and marriage temple is; Though parents grudge, and you, w'are met,
And cloistered in these living walls of jet. Though use make you apt to kill me, Let not to that, self-murder added be, And sacrilege, three sins in killing three.
Cruel and sudden, hast thou since Purpled thy nail, in blood of innocence?
Wherein could this flea guilty be, Except in that drop which it sucked from thee?
Yet thou triumph'st, and say'st that thou
Find'st not thy self, nor me the weaker now; 'Tis true; then learn how false, fears be: Just so much honor, when thou yield'st to me, Will waste, as this flea's death took life from thee.
Aucun commentaire:
Enregistrer un commentaire