42_EXAM icon indicating copy to clipboard operation
42_EXAM copied to clipboard

search and replace function

Open cuhlig42 opened this issue 1 year ago • 1 comments

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 <unistd.h>

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 avatar Sep 13 '23 16:09 cuhlig42

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?

cuhlig42 avatar Sep 13 '23 21:09 cuhlig42