First Upload
This commit is contained in:
58
12/ex2.c
Normal file
58
12/ex2.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "PointersLibs.h"
|
||||
|
||||
void SearchLongestWord(char s[], char **l)
|
||||
{
|
||||
*l = malloc(sizeof(char));
|
||||
char *ptr_s = s,
|
||||
*ptr_temp_s,
|
||||
*ptr_last_char = LastCharOfString(s);
|
||||
unsigned short max_lenght = ZERO;
|
||||
while (ptr_s < ptr_last_char)
|
||||
{
|
||||
|
||||
ptr_temp_s = IndexCharInPointers(ptr_s, ptr_last_char, ' ');
|
||||
if (ptr_temp_s - ptr_s > max_lenght)
|
||||
{
|
||||
max_lenght = ptr_temp_s - ptr_s;
|
||||
*l = realloc(*l, max_lenght);
|
||||
CopyPointers(*l, ptr_s, ptr_temp_s);
|
||||
(*LastCharOfString(*l)) = BACKSLASH_ZERO;
|
||||
}
|
||||
ptr_s = ptr_temp_s + ONE;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// exe 2
|
||||
// -----
|
||||
//
|
||||
// General : the program gets a string and searches for the longest
|
||||
// word in it and saves it.
|
||||
//
|
||||
// Input : a string and a pointer of pointers.
|
||||
//
|
||||
// Process : the program goes over the array and checks if each
|
||||
// word finds is longer than the last one that
|
||||
// was longest.
|
||||
//
|
||||
// Output : the longest word.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Proggramer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 21.11.19
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
typedef char string[MAX_SIZE_STRING];
|
||||
|
||||
string s = "Your feedback plays an important role in helping other buyers choose products and sellers.";
|
||||
char f;
|
||||
char *f1 = &f;
|
||||
char *f2 = &f1;
|
||||
SearchLongestWord(s, f2);
|
||||
printf("%s\n", f1);
|
||||
free(f1);
|
||||
}
|
||||
Reference in New Issue
Block a user