In fact there is no way to make that filter in C, you have to implement it all.
If you need the scanf()
you can use the library <string.h>
to analyze the url, I'll give you a solution without using it.
#include <stdio.h>
int main()
{
//creo un lugar para almacenar com, net, etc, nunca seran mas de 3 letras
char array[3];
//creo recorredores it y r, c es un entero porque convierto chars a enteros por tabla ascii
int c = 0, it = 0, r = 0;
while (c = getchar()) {
//si el iterador encuentra q esta en el 2do punto, vamos a guardarlo
if (it > 1 && r < 3) {
array[r] = c;
r++;
}
//si encuentro el punto, aumento al iterador
if (c == '.') it++;
//si el limite del almacenamiento llega, nos salimos del bucle
if (r >= 3) {
break;
}
}
//para imprimir, el arreglo de chars hacemos..
c = 0;
while (c < 3) {
printf("%c", array[c]);
c++;
}
return 0;
}
I do not like to use scanf()
for this situation, since I will be very efficient in the analysis of the url getchar()
is the adequate function for an analysis in time of execution, but you can condition the program so that it does with scanf()
if you like.
The logic is simple, if you count the points, you give with the domain com
, net
, etc.