Advertisement
BinYamin

VCF CSV android contacts

Aug 30th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 23.36 KB | None | 0 0
  1. /*
  2. VCF <-> CSV <-> VCF
  3. Everybody loves a neat contact list.
  4.  
  5. But as time passes and you meet more people at school, college, parties and offices the contact list grows longer and more chaotic and less manageable.
  6.  
  7. In earlier non-android phones transfering contact list was not an option but the contacts in my contact list were too dear to be just forgotten. I used to copy all the contacts I could (around 200-250 at a time) to the sim card, and then insert the sim in another phone and copy all from sim to phone. Repeat this 2-3 times and it was done. You can use this method to transfer your contacts from the old phone you have to an android phone.
  8.  
  9. Once your contacts are in an android phone it is a lot more eaiser, to transfer your contact list from one phone to another, thanks to vcf file format.
  10. Although vcfs are easy to transfer and merge and share, as a vcf file becomes larger it becomes more redundant and chaotic. As we combine contacts from different phones and merge different vcf's, the contact list becomes more and more redundant. Sometimes a contact number appears multiple times under the same name, sometimes the same number is saved under different names on two different phones and when your merge you have two copies.
  11. The code here can list all the repeating contacts.
  12.  
  13. Well, one problem down. But finding and deleting one contact a time in vcf is still neither easy nor feasible.
  14. It is impossible to handle and edit all the data of a vcf without getting a headache and two burning eyes.
  15. Would not it be better if you could convert your vcf file to a format which is gentle on eyes and easy to understand and edit? This is where csv files come it. csv files can be opened in spreadsheet (MS Excel etc) which means you can see ALL your contacts in a tabular format.
  16.  
  17. Once you have your contact list in a tabular form you can edit it any way you want. You can delete a cards with just one tap of delete button. Edit a name simply by clicking on it instead of going through all the trouble that you do through android. You can sort the list by name and merge the see if their are multiple vcards of the same person, and then merge them in one vcard, all this as easily as simple Ctrl+c and Ctrl+v.  
  18.  
  19. You can do that with this program, and after you are done deleting redundant and outdated contacts and making your contact list better you can convert it back to vcf format and Import it to your android phonr and voila!!.. Your contact list is brand new.
  20. :)
  21. ---*/
  22.  
  23.  
  24.  
  25. /*-----------------
  26.  * AuthorName: Sayyad Shaha Hassan
  27.  * Date: 23 August 2015
  28.  *
  29.  * This module converts vcf files to csv file.
  30.  * A csv file can be opened in a spreadsheet for easy access and editing.
  31.  *
  32.  * The supported version is 2.1
  33.  * Supported fields for each card are...
  34.  * Name: Prefix, First, Mid, Last, Suffix
  35.  * three Telephone numbers
  36.  * two email IDs
  37.  * Company, Title
  38.  * Note
  39.  * (one more extra field, other than the ones mentioned above)
  40.  *
  41.  * The fields other than the ones mentioned above will be added to NOTE section.
  42.  * Only ascii names are supported.
  43.  * commas used in NOTE will be replaced with period.
  44.  * Do not use commas in Names please.
  45.  */
  46.  
  47. #include<stdio.h>
  48. #include<string.h>
  49.  
  50. #define MAX_NAME 60
  51. #define MAX_FON 20
  52. #define MAX_XTRA 200
  53. FILE *gfpIn, *gfpOut;
  54.  
  55. typedef struct
  56. {
  57.     char szLastName[MAX_NAME];
  58.     char szFirstName[MAX_NAME];
  59.     char szMidName[MAX_NAME];
  60.     char szPreName[MAX_NAME];
  61.     char szSufName[MAX_NAME];
  62.  
  63.     char szFullName[MAX_NAME*4];
  64.  
  65.     char szTelCell[MAX_FON];
  66.     char szTelHome[MAX_FON];
  67.     char szTelX[MAX_FON];
  68.  
  69.     char szEmailHome[MAX_NAME];
  70.     char szEmailX[MAX_NAME];
  71.  
  72.     char szOrg[MAX_NAME];
  73.     char szTitle[MAX_NAME];
  74.  
  75.     char szNote[MAX_XTRA];
  76.     char szExtra[MAX_XTRA];
  77. } Card;
  78.  
  79. int Menu (int *choice);
  80. //displays menu and recieves a choice.
  81. int GetFileNames();
  82. //Gets filenames and returns handles.
  83. int VcfToCsv();
  84. //vcf file to csv
  85. int FindRepeat();
  86. //lists repeating numbers, uses CompareNumbers
  87. int CsvToVcf();
  88. //converts csv to vcf
  89. int FormatNumber (char szNum[MAX_FON]);
  90. //formats numbers as groups of 4 digits, right to left. eg ..x xxxx xxxx
  91. int CompareNumbers (char* Num1, char* Num2);
  92. //checks if lower 10 digits are the same (to ignore the std codes)
  93.  
  94. int
  95. main(
  96.      int argc,
  97.      char *argv[]
  98. )
  99. {
  100.     int ch;
  101.     do
  102.     {
  103.         Menu(&ch);
  104.         switch (ch)
  105.         {
  106.         //  vcf -> csv
  107.         case 1:
  108.             if (GetFileNames ())
  109.             {
  110.                 continue;
  111.             }
  112.  
  113.             if (VcfToCsv() < 0)
  114.             {
  115.                 printf("err in vcf2csf() ");
  116.                 return -2;
  117.             }
  118.             fclose( gfpIn);
  119.             fclose( gfpOut);
  120.             printf("\n Done....");
  121.             break;
  122.  
  123.         //csv -> vcf
  124.         case 2:
  125.             if (GetFileNames ())
  126.             {
  127.                 continue;
  128.             }
  129.  
  130.             if (CsvToVcf())
  131.             {
  132.                 printf("err in csfTovcf() ");
  133.                 return -2;
  134.             }
  135.             fclose( gfpIn);
  136.             fclose( gfpOut);
  137.             printf("\n Done....");
  138.             break;
  139.  
  140.         case 3:
  141.             FindRepeat();
  142.             break;
  143.  
  144.         case 5:
  145.             printf("\n Exiting...");
  146.             break;
  147.  
  148.         default:
  149.             printf("\n Invalid choice.");
  150.         break;
  151.         }
  152.     }while (ch!= 4);
  153.     return 0;
  154. }
  155.  
  156. int
  157. CsvToVcf(
  158.          )
  159. {
  160.     int i, flag, fillFlag;
  161.     Card card;
  162.     for(i = 0; !feof(gfpIn); i++)
  163.     {
  164.         flag = fillFlag = 0;
  165.         memset( &card, 0, sizeof(card));
  166.         //read a line
  167.         fillFlag += fscanf( gfpIn, "\n%[^,]s,", card.szLastName);
  168.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szFirstName);
  169.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szMidName);
  170.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szPreName);
  171.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szSufName);
  172.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szFullName);
  173.  
  174.         if (card.szPreName[0] != '\0')
  175.         {
  176.             sprintf(card.szFullName, "%s", card.szPreName);
  177.             flag++;
  178.         }
  179.         if (card.szFirstName[0] != '\0')
  180.         {
  181.             if(flag > 0)
  182.             {
  183.                 sprintf(card.szFullName, "%s %s", card.szFullName, card.szFirstName);
  184.                 flag++;
  185.             }
  186.             else    //firstName is first trm
  187.             {
  188.                 sprintf(card.szFullName, "%s%s", card.szFullName, card.szFirstName);
  189.                 flag++;
  190.             }
  191.         }
  192.         if (card.szMidName[0] != '\0')
  193.         {
  194.             if(flag > 0)
  195.             {
  196.                 sprintf(card.szFullName, "%s %s", card.szFullName, card.szMidName);
  197.                 flag++;
  198.             }
  199.             else
  200.             {
  201.                 sprintf(card.szFullName, "%s%s", card.szFullName, card.szMidName);
  202.                 flag++;
  203.             }
  204.         }
  205.         if (card.szLastName[0] != '\0')
  206.         {
  207.             if (flag > 0)
  208.             {
  209.                 sprintf(card.szFullName, "%s %s", card.szFullName, card.szLastName);
  210.                 flag++;
  211.             }
  212.             else
  213.             {
  214.                 sprintf(card.szFullName, "%s%s", card.szFullName, card.szLastName);
  215.                 flag++;
  216.             }
  217.         }
  218.         if (card.szSufName[0] != '\0')
  219.         {
  220.             if (flag > 0)
  221.             {
  222.                 sprintf(card.szFullName, "%s, %s", card.szFullName, card.szSufName);
  223.                 flag++;
  224.             }
  225.             else
  226.             {
  227.                 sprintf(card.szFullName, "%s,%s", card.szFullName, card.szSufName);
  228.                 flag++;
  229.             }
  230.         }
  231.  
  232.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szTelCell);
  233.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szTelHome);
  234.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szTelX);
  235.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szEmailHome);
  236.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szEmailX);
  237.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szOrg);
  238.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szTitle);
  239.         fillFlag += fscanf( gfpIn, ",%[^,]s,", card.szNote);
  240.         fillFlag += fscanf( gfpIn, ",%[^\n]s\n", card.szExtra);
  241.  
  242.         if (strcmp(card.szFirstName, "00FirstName") == 0)
  243.         {
  244.             i--;
  245.             continue;
  246.         }
  247.         //write the card
  248.         if (fillFlag > 0 )
  249.         {
  250.             fprintf( gfpOut, "BEGIN:VCARD\nVERSION:2.1\n");
  251.             fprintf( gfpOut, "N:%s;%s;%s;%s;%s\n", card.szLastName, card.szFirstName, card.szMidName, card.szPreName, card.szSufName);
  252.             fprintf( gfpOut, "FN:%s\n", card.szFullName);
  253.             if (card.szTelCell[0] != '\0')
  254.             {
  255.                 FormatNumber (card.szTelCell);
  256.                 fprintf( gfpOut, "TEL;CELL:%s\n", card.szTelCell);
  257.             }
  258.             if (card.szTelHome[0] != '\0')
  259.             {
  260.                 FormatNumber (card.szTelHome);
  261.                 fprintf( gfpOut, "TEL;HOME:%s\n", card.szTelHome);
  262.             }
  263.             if (card.szTelX[0] != '\0')
  264.             {
  265.                 FormatNumber (card.szTelX);
  266.                 fprintf( gfpOut, "TEL:%s\n", card.szTelX);
  267.             }
  268.             if (card.szEmailHome[0] != '\0')
  269.             {
  270.                 fprintf( gfpOut, "EMAIL;HOME:%s\n", card.szEmailHome);
  271.             }
  272.             if (card.szEmailX[0] != '\0')
  273.             {
  274.                 fprintf( gfpOut, "EMAIL:%s\n", card.szEmailX);
  275.             }
  276.             if (card.szOrg[0] != '\0')
  277.             {
  278.                 fprintf( gfpOut, "ORG:%s\n", card.szOrg);
  279.             }
  280.             if (card.szTitle[0] != '\0')
  281.             {
  282.                 fprintf( gfpOut, "TITLE:%s\n", card.szTitle);
  283.             }
  284.             if (card.szNote[0] != '\0')
  285.             {
  286.                 fprintf( gfpOut, "NOTE:%s\n", card.szNote);
  287.             }
  288.             if (card.szExtra[0] != '\0')
  289.             {
  290.                 fprintf( gfpOut, "%s\n", card.szExtra);
  291.             }
  292.             fprintf( gfpOut, "END:VCARD\n");
  293.         }
  294.     }
  295.     printf("\n%d Contacts.", i-1);
  296.     return 0;
  297. }
  298.  
  299. int
  300. FormatNumber (
  301.               char szNum[MAX_FON]
  302.               )
  303. {
  304.     int i, j, len;
  305.     char szTemp[MAX_FON];
  306.  
  307.     //removing spaces
  308.     for ( j = i = 0; szNum[i] != '\0'; i++)
  309.     {
  310.         if ( (szNum[i] == '+') || ((szNum[i] <= '9') && (szNum[i] >= '0')))
  311.         {
  312.             szTemp[j++] = szNum[i];
  313.         }
  314.     }
  315.     szTemp[j] = '\0';
  316.     len = strlen(szTemp);
  317.  
  318.     //copying szTemp to szNum. format ...xx xxxx xxxx
  319.     i = j%4;
  320.     strncpy(szNum, szTemp, i);
  321.     j = i;
  322.     while ( len > j)
  323.     {
  324.         szNum[i++] = ' ';
  325.         strncpy(szNum+i, szTemp+j, 4);
  326.         i += 4;
  327.         j += 4;
  328.     }
  329.     szNum[i] = '\0';
  330.     return 0;
  331. }
  332.  
  333. int
  334. CompareNumbers(
  335.                char* Num1,
  336.                char* Num2
  337.                )
  338. {
  339.     char rev1[MAX_FON], rev2[MAX_FON];
  340.  
  341.     strcpy (rev1, Num1);
  342.     strcpy (rev2, Num2);
  343.  
  344.     strrev(rev1);
  345.     strrev(rev2);
  346.  
  347.     if (strncmp (rev1, rev2, 12) == 0)
  348.     {
  349.         return 0;
  350.     }
  351.  
  352.     return -1;
  353. }
  354.  
  355.  
  356. int
  357. AppendAsNote(
  358.              Card* card,
  359.              char* szToAdd
  360.              )
  361. {
  362.     printf("\nThe \"%s\" of \"%s %s\" could not be saved, but added to Notes. Please save it manually\n", szToAdd, card->szFirstName, card->szLastName);
  363.     sprintf (card->szNote, "%s. %s", card->szNote, szToAdd);
  364.     return 0;
  365. }
  366.  
  367. int
  368. VcfToCsv(
  369.         )
  370. {
  371.     unsigned int j, i;
  372.     Card card;
  373.     char szHead[50], szTemp[100];
  374.     int FilledFlags;
  375.     /*
  376.         bit(1,2,3):1,2,4 if set => Cell, Home, and X phone filled, respectively & individually.
  377.         bit(4,5):8,16 => EmailHome, emailX filled
  378.         bit(6):32 => Extra field filled
  379.         bit(8):128 => break outer loop
  380.     */
  381.  
  382.     //dummy entry/Header.
  383.     fprintf( gfpOut, "00LastName,00FirstName,00MidName,Prefix,Suffix,");
  384.     fprintf( gfpOut, "FullName,");
  385.     fprintf( gfpOut, "+ 9190 1234 5678,+9191 1234 1234,55 1123,");
  386.     fprintf( gfpOut, "email@home.in,email@other.in,Org,Title,Note");
  387.     fprintf( gfpOut, ",Extra\n");
  388.  
  389.     for(j = 0; !feof(gfpIn); j++)    //1 card
  390.     {
  391.         memset (&card, '\0', sizeof(card));
  392.         FilledFlags = 0;
  393.         while (1)   //read a card
  394.         {
  395.             //read header
  396.             if ( 0 >= fscanf (gfpIn, "\n%[^:]s", szHead))
  397.             {
  398.                 FilledFlags = (FilledFlags | 128);
  399.                 break;
  400.             }
  401.  
  402.             //Note
  403.             if( strncmp(szHead, "NOTE", 4) == 0)
  404.             {
  405.                 fscanf(gfpIn, ":%[^\n]s\n", card.szNote);
  406.                 for (i=0; card.szNote[i] != '\0'; i++)
  407.                 {
  408.                     if( card.szNote[i] == ',')
  409.                     {
  410.                         card.szNote[i] = '.';
  411.                     }
  412.                 }
  413.             }
  414.             else    //name
  415.             if( strncmp( szHead, "N", 1) == 0)
  416.             {
  417.                 fscanf (gfpIn, ":%[^;]s", card.szLastName);
  418.                 fscanf (gfpIn, ";%[^;]s", card.szFirstName);
  419.                 fscanf (gfpIn, ";%[^;]s", card.szMidName);
  420.                 fscanf (gfpIn, ";%[^;]s", card.szPreName);
  421.                 fscanf (gfpIn, ";%[^\n]s", card.szSufName);
  422.             }
  423.             else    //Telephones
  424.             if( strncmp (szHead, "TEL;CELL", 8) == 0)
  425.             {
  426.                 if ((FilledFlags&01) == 0)    //no overwrite Logic
  427.                 {
  428.                     fscanf (gfpIn, ":%[^\n]s", card.szTelCell );
  429.                     FormatNumber (card.szTelCell);
  430.                     FilledFlags = (FilledFlags | 01);
  431.                 }
  432.                 else if ((FilledFlags&04)==0)
  433.                 {
  434.                     fscanf (gfpIn, ":%[^\n]s", card.szTelX );
  435.                     FormatNumber (card.szTelX);
  436.                     FilledFlags = (FilledFlags | 04);
  437.                 }
  438.                 else if ((FilledFlags&02)==0)
  439.                 {
  440.                     fscanf (gfpIn, ":%[^\n]s", card.szTelHome);
  441.                     FormatNumber (card.szTelHome);
  442.                     FilledFlags = (FilledFlags | 02);
  443.                 }
  444.                 else
  445.                 {
  446.                     fscanf (gfpIn, ":%[^\n]s", szTemp);
  447.                     AppendAsNote (&card, szTemp);
  448.                 }
  449.             }
  450.             else
  451.             if( strncmp (szHead, "TEL;HOME", 8) == 0)
  452.             {
  453.                 if ((FilledFlags&02) == 0)
  454.                 {
  455.                     fscanf (gfpIn, ":%[^\n]s", card.szTelHome);
  456.                     FormatNumber (card.szTelHome);
  457.                     FilledFlags = (FilledFlags | 02);
  458.                 }
  459.                 else if ((FilledFlags&04)==0)
  460.                 {
  461.                     fscanf (gfpIn, ":%[^\n]s", card.szTelX);
  462.                     FormatNumber (card.szTelX);
  463.                     FilledFlags = (FilledFlags | 04);
  464.                 }
  465.                 else if ((FilledFlags&1)==0)
  466.                 {
  467.                     fscanf (gfpIn, ":%[^\n]s", card.szTelCell );
  468.                     FormatNumber (card.szTelCell);
  469.                     FilledFlags = (FilledFlags | 01);
  470.                 }
  471.                 else
  472.                 {
  473.                     fscanf (gfpIn, ":%[^\n]s", szTemp);
  474.                     AppendAsNote (&card, szTemp);
  475.                 }
  476.             }
  477.             else
  478.             if( strncmp (szHead, "TEL", 3) == 0)
  479.             {
  480.                 if ((FilledFlags&04)==0)
  481.                 {
  482.                     fscanf (gfpIn, ":%[^\n]s", card.szTelX);
  483.                     FormatNumber (card.szTelX);
  484.                     FilledFlags = (FilledFlags | 04);
  485.                 }
  486.                 else
  487.                 if ((FilledFlags&01) == 0)    //no overwrite Logic
  488.                 {
  489.                     fscanf (gfpIn, ":%[^\n]s", card.szTelCell);
  490.                     FormatNumber (card.szTelCell);
  491.                     FilledFlags = (FilledFlags | 01);
  492.                 }
  493.                 else
  494.                 if ((FilledFlags&02)==0)
  495.                 {
  496.                     fscanf (gfpIn, ":%[^\n]s", card.szTelHome);
  497.                     FormatNumber (card.szTelHome);
  498.                     FilledFlags = (FilledFlags | 02);
  499.                 }
  500.                 else
  501.                 {
  502.                     fscanf (gfpIn, ":%[^\n]s", szTemp);
  503.                     AppendAsNote (&card, szTemp);
  504.                 }
  505.             }
  506.             else
  507.             if (strncmp (szHead, "EMAIL;HOME", 10) == 0)
  508.             {
  509.                 if ((FilledFlags&8)==0)
  510.                 {
  511.                     fscanf (gfpIn, ":%[^\n]s", card.szEmailHome);
  512.                     FilledFlags = (FilledFlags | 8);
  513.                 }
  514.                 else
  515.                 if((FilledFlags&16)==0)
  516.                 {
  517.                     fscanf (gfpIn, ":%[^\n]s", card.szEmailX);
  518.                     FilledFlags = (FilledFlags | 16);
  519.                 }
  520.                 else
  521.                 {
  522.                     fscanf(gfpIn, ":%[^\n]s", szTemp);
  523.                     AppendAsNote (&card, szTemp);
  524.                 }
  525.             }
  526.             else
  527.             if (strncmp (szHead, "EMAIL", 5) == 0)
  528.             {
  529.                 if((FilledFlags & 16) == 0)
  530.                 {
  531.                     fscanf (gfpIn, ":%[^\n]s", card.szEmailX);
  532.                     FilledFlags = (FilledFlags | 16);
  533.                 }
  534.                 else if ((FilledFlags & 8) == 0)
  535.                 {
  536.                     fscanf (gfpIn, ":%[^\n]s", card.szEmailHome);
  537.                     FilledFlags = (FilledFlags | 8);
  538.                 }
  539.                 else
  540.                 {
  541.                     fscanf(gfpIn, ":%[^\n]s", szTemp);
  542.                     AppendAsNote (&card, szTemp);
  543.                 }
  544.             }
  545.             else
  546.             if (strncmp (szHead, "ORG", 3) == 0)
  547.             {
  548.                 fscanf (gfpIn, ":%[^\n]s", card.szOrg );
  549.             }
  550.             else
  551.             if (strncmp (szHead, "TITLE", 3) == 0)
  552.             {
  553.                 fscanf (gfpIn, ":%[^\n]s", card.szTitle );
  554.             }
  555.             else
  556.             if ( strncmp (szHead, "END", 3) == 0)
  557.             {
  558.                 fscanf (gfpIn, ":%[^\n]s\n", &szTemp);
  559.                 break;
  560.             }
  561.             else
  562.             if (( strncmp(szHead, "BEGIN", 5) == 0) || ( strcmp(szHead, "VERSION") == 0))
  563.             {
  564.                 //skip line
  565.                 fscanf (gfpIn, "%[^\n]s\n", &szTemp);
  566.             }
  567.             else
  568.             if ( strncmp(szHead, "FN", 2) == 0)
  569.             {
  570.                 fscanf (gfpIn, "%[^\n]s\n", &szTemp);
  571.             }
  572.             else
  573.             {//append to extra
  574.                 fscanf (gfpIn, "%[^\n]s\n", &szTemp);
  575.                 if ((FilledFlags & 32) == 0)
  576.                 {
  577.                     sprintf(card.szExtra, "%s%s", szHead, szTemp);
  578.                     FilledFlags = (FilledFlags | 32);
  579.                 }
  580.                 else
  581.                 {
  582.                     char szDump[60];
  583.                     sprintf (szDump, "%s %s", szHead, szTemp+1);
  584.                     AppendAsNote (&card, szDump);
  585.                 }
  586.             }
  587.         }   //next line/card
  588.  
  589.         if ((FilledFlags&128) != 128)
  590.         {
  591.             //Write the card to csv.
  592.             fprintf( gfpOut, "%s,%s,%s,%s,%s,", card.szLastName, card.szFirstName, card.szMidName, card.szPreName, card.szSufName);
  593.             fprintf( gfpOut, "%s,", card.szFullName);
  594.             fprintf( gfpOut, "%s,%s,%s,", card.szTelCell, card.szTelHome, card.szTelX);
  595.             fprintf( gfpOut, "%s,%s,%s,%s,%s", card.szEmailHome, card.szEmailX, card.szOrg, card.szTitle, card.szNote);
  596.             fprintf( gfpOut, ",%s\n", card.szExtra);
  597.             printf("\r%4u", (j+1));
  598.         }
  599.     }   //while, next card
  600.  
  601.     printf(" contacts found.");
  602.     return j;
  603. }
  604.  
  605. int
  606. FindRepeat(
  607.             )
  608. {
  609.     int i, iMax, j, ch, no, ret;
  610.     char Dummy[50], szFile[50];
  611.     char szContact[2000][20];
  612.     short int szIndex[2000];
  613.     char szNames[2000][60];
  614.     Card card;
  615.  
  616.     printf("Enter csv filename.");
  617.     scanf("%s", szFile);
  618.  
  619.     do
  620.     {
  621.         gfpIn = fopen(szFile, "r");
  622.         if (gfpIn == NULL)
  623.         {
  624.             printf("File could not be opened.");
  625.             return -1;
  626.         }
  627.         printf("Processing %s for duplicate contacts.\n", Dummy);
  628.         for (i = iMax = 0;  !feof(gfpIn); i++)
  629.         {
  630.             memset(&card, 0, sizeof(card));
  631.             fscanf(gfpIn, "\n%[^,]s", card.szLastName);
  632.             fscanf(gfpIn, ",%[^,]s", card.szFirstName);
  633.             fscanf(gfpIn, ",%[^,]s", card.szMidName);
  634.             fscanf(gfpIn, ",%[^,]s", card.szPreName);
  635.             fscanf(gfpIn, ",%[^,]s", card.szSufName);
  636.             fscanf(gfpIn, ",%[^,]s", card.szFullName);    //name
  637.             sprintf(szNames[i], "%s %s %s %s %s",card.szPreName, card.szFirstName, card.szMidName, card.szLastName, card.szSufName);
  638.  
  639.             //Tel;CELL
  640.             ret = fscanf(gfpIn, ",%[^,]s,", szContact[iMax]);
  641.             if ( ret > 0)
  642.             {
  643.                 szIndex[iMax] = i;
  644.                 iMax++;
  645.             }
  646.  
  647.             //TellHome
  648.             ret = fscanf(gfpIn, ",%[^,]s", szContact[iMax]);
  649.             if ( ret > 0)
  650.             {
  651.                 szIndex[iMax] = i;
  652.                 iMax++;
  653.             }
  654.  
  655.             ret = fscanf(gfpIn, ",%[^,]s", szContact[iMax]);
  656.             if ( ret > 0)
  657.             {
  658.                 szIndex[iMax] = i;
  659.                 iMax++;
  660.             }
  661.  
  662.             fscanf(gfpIn, ",%[^,]s", Dummy);
  663.             fscanf(gfpIn, ",%[^,]s", Dummy);
  664.             fscanf(gfpIn, ",%[^,]s", Dummy);
  665.             fscanf(gfpIn, ",%[^,]s", Dummy);
  666.             fscanf(gfpIn, ",%[^,]s", Dummy);
  667.             fscanf(gfpIn, ",%[^\n]s", Dummy);
  668.         }
  669.  
  670.         //comparing numbers
  671.         printf("\n card. Number1,     Number2         SameCard?");
  672.         for ( i = no = 0; i < iMax; i++)
  673.         {
  674.             for (j = i+1; j < iMax; j++)
  675.             {
  676.                 if (CompareNumbers(szContact[i], szContact[j]) == 0)
  677.                 {
  678.                     printf("\n %3i: %3i   %18s %c %s", no+1, szIndex[i]+1, szContact[i], (szIndex[i]==szIndex[j]?'*':' '), szNames[szIndex[i]]);
  679.                     printf("\n      %3i   %18s   %s", szIndex[j]+1, szContact[j], szNames[szIndex[j]]);
  680.                     no++;
  681.                 }
  682.             }
  683.         }
  684.         fclose(gfpIn);
  685.         printf("\n %d repeats found.", no);
  686.         printf("\nDelete the repeating contacts. \nPress 2 to refresh list, Press 1 if done: ");
  687.         scanf("%d", &ch);
  688.     }while (ch==2);
  689.     return 0;
  690. }
  691.  
  692. int
  693. GetFileNames(
  694.         )
  695. {
  696.     char szFileIn[100], szFileOut[100];
  697.  
  698.     printf("\nEnter Input file: ");
  699.     scanf("%s", szFileIn);
  700.  
  701.     printf("\nEnter Output file: ");
  702.     scanf("%s", szFileOut);
  703.  
  704.     gfpIn = fopen (szFileIn, "r");
  705.     if (gfpIn == NULL)
  706.     {
  707.         printf("Error opening Infile.");
  708.         return -1;
  709.     }
  710.  
  711.     gfpOut = fopen (szFileOut, "w");
  712.  
  713.     if (gfpOut == NULL)
  714.     {
  715.         printf("Error opening Outfile.");
  716.         return -1;
  717.     }
  718.  
  719.     printf("\n Processing... %s -> %s", szFileIn, szFileOut);
  720.     return 0;
  721. }
  722.  
  723. int
  724. Menu (
  725.         int *choice
  726.         )
  727. {
  728.     do
  729.     {
  730.         printf ("\n 1. vcf to csv \n 2. csv to vcf \n 3. Find Repeating numbers \n 4. Exit\n Select: ");
  731.         scanf ("%d", choice);
  732.     }while((*choice > 4) || ( *choice < 1));
  733.     return 0;
  734. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement