I've got a program that reads a bunch of tweets from a .txt file into a 2D char array. Each tweet is a new row in the array, while the characters in each string make up the columns (or at least I think that's how it works). I'm trying to write a function that will find the index of the array that contains the tweet with the greatest amount of characters (or longest string). This isn't a full representation of the program, but here is what I've got so far:
Code:
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#define MAX_TWEET_SIZE 200
#define MAX_TWEETS 1000
int max_index(array[][MAX_TWEET_SIZE], int tweets);
int main(int argc, char* argv[]){
char tweets[MAX_TWEETS][MAX_TWEETS_SIZE];
int num_tweets = 0;
int i = 0;
while(fgets(tweets[i], MAX_TWEET_SIZE, tweetFile) != NULL){
i++;
num_tweets++;
}
printf("The longest tweet is #%d.\n", max_index(tweets, num_tweets));
(end of main function to this point)
}
int max_index(char array[][MAX_TWEET_SIZE], int tweets){
int i, index;
for(i = 1; i <= tweets; i++){
if(strlen(array + i) > strlen(array + i - 1)){
index = i;
}
}
return index;
}
I'm still fairly new to programming and dealing with pointers is pretty confusing for me at this point. I understand that my usage of 'strlen()' is probably not correct as that is only error message I'm getting when I compile. I've been looking around to try and understand strlen() a little better but I can't find any examples that fit my problem here, and I have just hit a wall. I'm not looking to be handed an answer, but if someone has some advice to help me understand how to get this program working it'd be greatly appreciated!