Thread: error about strcpy and strcmp

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Well I gave you several things to change and you only changed two of them. Salary is still an array.

    Does your compiler not warn you?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Quote Originally Posted by kkkcj View Post
    Code:
    if(id == P[i].id ==0){
                found =1;
    this is mean if the id user enter same as id store in system. print all the details and another question is the compiler will display the details even though the user user enter the wrong ID
    Then just delete the ==0 from the if expression.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    but i'm declare the salary as the integer type ...i'm not sure which part you refer to and after i change the code become (id == P[i].id ) the compiler will straight print no record founded with this id.no matter id exit or not
    Last edited by kkkcj; 12-18-2017 at 12:26 AM.

  4. #19
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    >but i'm declare the salary as the integer type ...i'm not sure which part you refer to and after i change the code become (id == P[i].id )
    salary should not be an array type for the same reason you didn't make id an array type in the structure. The names are char arrays because they have to be, so what you do with them (like call strcpy) is a little different from things that can be expressed as one number.

    I mean, presumably P is an array of employees, so each P[i] has everything about one employee; their name arrays, their salary integer, etc. If salary stays an int[20] it's just a lot of extra space when you only need one number.

    "P" is a rather terrible variable name by the way for something so central to the program.
    Last edited by whiteflags; 12-18-2017 at 01:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp and strcpy error
    By behzad_shabani in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2008, 04:15 PM
  2. help with #define, strcmp, and strcpy
    By doc_watson2007 in forum C Programming
    Replies: 8
    Last Post: 12-20-2004, 10:50 PM
  3. strcpy()&strcmp()
    By mr alison in forum C Programming
    Replies: 5
    Last Post: 10-10-2002, 02:26 PM
  4. strcpy & strcmp, what is wrong?
    By Silverdream in forum C Programming
    Replies: 7
    Last Post: 02-13-2002, 03:36 PM

Tags for this Thread