ricardo_1977 Posted April 28, 2009 at 03:12 PM Report #259714 Posted April 28, 2009 at 03:12 PM Boa tarde. tenho de fazer uma função que retire os dados de um ficheiro csv. o ficheiro tem os sequintes dados: NIF;nome;endereco 9000011000;Jon Yang;3761 N. 14th St 9000011001;Eugene Huang;2243 W St. 9000011002;Ruben Torres;5844 Linden Land (...) eu preciso de retirar para variaveis:nif,nome,endereço cada um dos dados especificos enao estou a conseguir. agradecia ajuda
bruno1234 Posted April 28, 2009 at 03:15 PM Report #259716 Posted April 28, 2009 at 03:15 PM Tens q ler o ficheiro linha a linha e separar por ';' A standard library do C tem uma função q te dá uma boa ajuda para isso: strtok. Pesquisa no google ou num livro de C como utilizar esta função e tens o teu problema resolvido. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos
ricardo_1977 Posted April 28, 2009 at 03:40 PM Author Report #259719 Posted April 28, 2009 at 03:40 PM n esta a funcionar
bruno1234 Posted April 28, 2009 at 03:59 PM Report #259729 Posted April 28, 2009 at 03:59 PM Tens aqui um exemplo q tirei da net, está em C++, mas a unica diferença está nos includes, o resto é igual. /* strtok example */ #include <stdio.h> #include <string.h> int main () { char str[] ="- This, a sample string."; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok (str," ,.-"); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " ,.-"); } return 0; } Output: Splitting string "- This, a sample string." into tokens: This a sample string Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos
Rui Carlos Posted April 28, 2009 at 04:14 PM Report #259734 Posted April 28, 2009 at 04:14 PM Também podes tentar usar a função scanf (e semelhantes). Rui Carlos Gonçalves
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now