JCluzet / 42_EXAM

A program almost identical to the 42 EXAMS for practice. (Pool EXAM & Stud EXAM)
Other
1.16k stars 88 forks source link

search and replace function #125

Open cuhlig42 opened 1 year ago

cuhlig42 commented 1 year ago

hello my question is what if as example a number was writen as on of the 2 argument for search or replace ? should it not display in this scenario the normal string without any changes?

like: this is your code:

include

int main(int ac, char **av) { int i;

i = 0;
if (ac == 4)
{
    if(((av[2][0] >= 'a' && av[2][0]<= 'z') || (av[2][0] >= 'A' && av[2][0]<= 'Z')) && av[2][1] == '\0')
        if (((av[3][0] >= 'a' && av[2][0]<= 'z') || (av[3][0] >= 'A' && av[3][0]<= 'Z')) && av[3][1] == '\0')
        {
            while (av[1][i] != '\0')
            {
                if (av[1][i] == av[2][0])
                        av[1][i] = av[3][0];
                write(1, &av[1][i], 1);
                i++;
            }
        }
}
write(1, "\n", 1);

} and the second question is:

the subject says: If the second argument is not contained in the first one (the string) then the program simply rewrites the string followed by a newline.

where in the code is the line for this part?

and i know the examples show just a empty line but this was kinda wierd

cuhlig42 commented 1 year ago

oh a other thing the jump in my eye is this: if(((argv[2][0] >= 'a' && argv[2][0]<= 'z') || (argv[2][0] >= 'A' && argv[2][0]<= 'Z')) && argv[2][1] == '\0') why is there for the little letters no condition for a \0 check?