Thread: Two easy vector questions.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Pecado's Avatar
    Join Date
    Sep 2010
    Posts
    34

    Question Two easy vector questions.

    Hello everyone. My questions are the following:

    1) In a program, different values to a vector are given(e.g.: vector[1]=3; vector[2]=5; ...)

    Declaration: int vector[5]={1,5,6,7,2};
    And at the time of saving the info into a text file it would be something like this:
    Code:
    fprintf(fp,"%d %d %d %d", vector[1], vector[2], vector[3], vector[4])
    and the fscanf:
    Code:
    fscanf(fp,"%d %d %d %d", &vector[1], &vector[2], &vector[3], &vector[4])
    Imagine that it is a longer vector, then it would be a mess.

    Can there be written something like this?:
    Code:
    fprintf(fp,"%d %d %d %d", vector[i])
    
    fscanf(fp,"%d %d %d %d", &vector[i])
    2) I've heard around that there is a command or statement used to find values in a vector. Maybe:
    Code:
    while(5 in vector){printf("There is a 5 in the vector.");}
    But couldn't figure out how this is. Any help would be apreciated, if something isn't clear tell me, thanks.
    Last edited by Pecado; 10-17-2010 at 12:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  2. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  3. Replies: 20
    Last Post: 05-25-2002, 07:14 PM
  4. EASY GUI development.. like with Qt?
    By rezonax in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2001, 01:18 PM

Tags for this Thread