Borrar filtros
Borrar filtros

check an phone number area code with strncmp

1 visualización (últimos 30 días)
jarvan
jarvan el 18 de Nov. de 2014
Comentada: Guillaume el 18 de Nov. de 2014
The phone number should be ###-###-####, which is including the dash. I am writing a function to determine whether a string form a phone format and a right area code checking for a three character combination followed by a dash. however, if I put dash in the string, it means to subtract. How can I avoid that?
function y = areacode(pnumber)
usernum = input('Enter your number with dash : ' )
if strncmp(pnumber,usernum,4)== 1
disp('The area code is same!')
else
disp('The area code is not same.')
end
end

Respuesta aceptada

Phillip
Phillip el 18 de Nov. de 2014
Hi
Type
help input
at the command prompt and have a look at what it says. Your answer is right there.
Regards, Phil
  2 comentarios
jarvan
jarvan el 18 de Nov. de 2014
i should put in '' to avoid it ,thank you
Guillaume
Guillaume el 18 de Nov. de 2014
You should put in 's' as in
input('enter your number', 's')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by